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