| 1 | // RUN: %check_clang_tidy %s cppcoreguidelines-macro-usage -std=c++17-or-later %t -- -header-filter=.* -system-headers -- |
| 2 | |
| 3 | #ifndef INCLUDE_GUARD |
| 4 | #define INCLUDE_GUARD |
| 5 | |
| 6 | #define PROBLEMATIC_CONSTANT 0 |
| 7 | // CHECK-MESSAGES: [[@LINE-1]]:9: warning: macro 'PROBLEMATIC_CONSTANT' used to declare a constant; consider using a 'constexpr' constant |
| 8 | |
| 9 | #define PROBLEMATIC_CONSTANT_CHAR '0' |
| 10 | // CHECK-MESSAGES: [[@LINE-1]]:9: warning: macro 'PROBLEMATIC_CONSTANT_CHAR' used to declare a constant; consider using a 'constexpr' constant |
| 11 | |
| 12 | #define PROBLEMATIC_CONSTANT_WIDE_CHAR L'0' |
| 13 | // CHECK-MESSAGES: [[@LINE-1]]:9: warning: macro 'PROBLEMATIC_CONSTANT_WIDE_CHAR' used to declare a constant; consider using a 'constexpr' constant |
| 14 | |
| 15 | #define PROBLEMATIC_CONSTANT_UTF8_CHAR u8'0' |
| 16 | // CHECK-MESSAGES: [[@LINE-1]]:9: warning: macro 'PROBLEMATIC_CONSTANT_UTF8_CHAR' used to declare a constant; consider using a 'constexpr' constant |
| 17 | |
| 18 | #define PROBLEMATIC_CONSTANT_UTF16_CHAR u'0' |
| 19 | // CHECK-MESSAGES: [[@LINE-1]]:9: warning: macro 'PROBLEMATIC_CONSTANT_UTF16_CHAR' used to declare a constant; consider using a 'constexpr' constant |
| 20 | |
| 21 | #define PROBLEMATIC_CONSTANT_UTF32_CHAR U'0' |
| 22 | // CHECK-MESSAGES: [[@LINE-1]]:9: warning: macro 'PROBLEMATIC_CONSTANT_UTF32_CHAR' used to declare a constant; consider using a 'constexpr' constant |
| 23 | |
| 24 | #define PROBLEMATIC_FUNCTION(x, y) ((a) > (b) ? (a) : (b)) |
| 25 | // CHECK-MESSAGES: [[@LINE-1]]:9: warning: function-like macro 'PROBLEMATIC_FUNCTION' used; consider a 'constexpr' template function |
| 26 | |
| 27 | #define PROBLEMATIC_VARIADIC(...) (__VA_ARGS__) |
| 28 | // CHECK-MESSAGES: [[@LINE-1]]:9: warning: variadic macro 'PROBLEMATIC_VARIADIC' used; consider using a 'constexpr' variadic template function |
| 29 | |
| 30 | #define PROBLEMATIC_VARIADIC2(x, ...) (__VA_ARGS__) |
| 31 | // CHECK-MESSAGES: [[@LINE-1]]:9: warning: variadic macro 'PROBLEMATIC_VARIADIC2' used; consider using a 'constexpr' variadic template function |
| 32 | |
| 33 | // These are all examples of common macros that shouldn't have constexpr suggestions. |
| 34 | #define CONCAT_NAME(a, b) a##b |
| 35 | |
| 36 | #define CONCAT_STR(a, b) #a #b |
| 37 | |
| 38 | #define COMMA , |
| 39 | |
| 40 | #define NORETURN [[noreturn]] |
| 41 | |
| 42 | #define DEPRECATED attribute((deprecated)) |
| 43 | |
| 44 | #if LIB_EXPORTS |
| 45 | #define DLLEXPORTS __declspec(dllexport) |
| 46 | #else |
| 47 | #define DLLEXPORTS __declspec(dllimport) |
| 48 | #endif |
| 49 | |
| 50 | #endif |
| 51 | |