1*89a1d03eSRichard // RUN: %check_clang_tidy %s bugprone-lambda-function-name %t
2*89a1d03eSRichard
Foo(const char * a,const char * b,int c)3*89a1d03eSRichard void Foo(const char* a, const char* b, int c) {}
4*89a1d03eSRichard
5*89a1d03eSRichard #define FUNC_MACRO Foo(__func__, "", 0)
6*89a1d03eSRichard #define FUNCTION_MACRO Foo(__FUNCTION__, "", 0)
7*89a1d03eSRichard #define EMBED_IN_ANOTHER_MACRO1 FUNC_MACRO
8*89a1d03eSRichard
Positives()9*89a1d03eSRichard void Positives() {
10*89a1d03eSRichard [] { __func__; }();
11*89a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: inside a lambda, '__func__' expands to the name of the function call operator; consider capturing the name of the enclosing function explicitly [bugprone-lambda-function-name]
12*89a1d03eSRichard [] { __FUNCTION__; }();
13*89a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: inside a lambda, '__FUNCTION__' expands to the name of the function call operator; consider capturing the name of the enclosing function explicitly [bugprone-lambda-function-name]
14*89a1d03eSRichard [] { FUNC_MACRO; }();
15*89a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: inside a lambda, '__func__' expands to the name of the function call operator; consider capturing the name of the enclosing function explicitly [bugprone-lambda-function-name]
16*89a1d03eSRichard [] { FUNCTION_MACRO; }();
17*89a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: inside a lambda, '__FUNCTION__' expands to the name of the function call operator; consider capturing the name of the enclosing function explicitly [bugprone-lambda-function-name]
18*89a1d03eSRichard [] { EMBED_IN_ANOTHER_MACRO1; }();
19*89a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: inside a lambda, '__func__' expands to the name of the function call operator; consider capturing the name of the enclosing function explicitly [bugprone-lambda-function-name]
20*89a1d03eSRichard }
21*89a1d03eSRichard
22*89a1d03eSRichard #define FUNC_MACRO_WITH_FILE_AND_LINE Foo(__func__, __FILE__, __LINE__)
23*89a1d03eSRichard #define FUNCTION_MACRO_WITH_FILE_AND_LINE Foo(__FUNCTION__, __FILE__, __LINE__)
24*89a1d03eSRichard #define EMBED_IN_ANOTHER_MACRO2 FUNC_MACRO_WITH_FILE_AND_LINE
25*89a1d03eSRichard
Negatives()26*89a1d03eSRichard void Negatives() {
27*89a1d03eSRichard __func__;
28*89a1d03eSRichard __FUNCTION__;
29*89a1d03eSRichard
30*89a1d03eSRichard // __PRETTY_FUNCTION__ should not trigger a warning because its value is
31*89a1d03eSRichard // actually potentially useful.
32*89a1d03eSRichard __PRETTY_FUNCTION__;
33*89a1d03eSRichard [] { __PRETTY_FUNCTION__; }();
34*89a1d03eSRichard
35*89a1d03eSRichard // Don't warn if __func__/__FUNCTION is used inside a macro that also uses
36*89a1d03eSRichard // __FILE__ and __LINE__, on the assumption that __FILE__ and __LINE__ will
37*89a1d03eSRichard // be useful even if __func__/__FUNCTION__ is not.
38*89a1d03eSRichard [] { FUNC_MACRO_WITH_FILE_AND_LINE; }();
39*89a1d03eSRichard [] { FUNCTION_MACRO_WITH_FILE_AND_LINE; }();
40*89a1d03eSRichard [] { EMBED_IN_ANOTHER_MACRO2; }();
41*89a1d03eSRichard }
42