xref: /llvm-project/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/macro-usage.cpp (revision b06da39cae0f7e2c6b8bc0bb03b734f9715c0bf3)
189a1d03eSRichard // RUN: %check_clang_tidy %s cppcoreguidelines-macro-usage -std=c++17-or-later %t -- -header-filter=.* -system-headers --
289a1d03eSRichard 
389a1d03eSRichard #ifndef INCLUDE_GUARD
489a1d03eSRichard #define INCLUDE_GUARD
589a1d03eSRichard 
689a1d03eSRichard #define PROBLEMATIC_CONSTANT 0
789a1d03eSRichard // CHECK-MESSAGES: [[@LINE-1]]:9: warning: macro 'PROBLEMATIC_CONSTANT' used to declare a constant; consider using a 'constexpr' constant
889a1d03eSRichard 
989a1d03eSRichard #define PROBLEMATIC_CONSTANT_CHAR '0'
1089a1d03eSRichard // CHECK-MESSAGES: [[@LINE-1]]:9: warning: macro 'PROBLEMATIC_CONSTANT_CHAR' used to declare a constant; consider using a 'constexpr' constant
1189a1d03eSRichard 
1289a1d03eSRichard #define PROBLEMATIC_CONSTANT_WIDE_CHAR L'0'
1389a1d03eSRichard // CHECK-MESSAGES: [[@LINE-1]]:9: warning: macro 'PROBLEMATIC_CONSTANT_WIDE_CHAR' used to declare a constant; consider using a 'constexpr' constant
1489a1d03eSRichard 
1589a1d03eSRichard #define PROBLEMATIC_CONSTANT_UTF8_CHAR u8'0'
1689a1d03eSRichard // CHECK-MESSAGES: [[@LINE-1]]:9: warning: macro 'PROBLEMATIC_CONSTANT_UTF8_CHAR' used to declare a constant; consider using a 'constexpr' constant
1789a1d03eSRichard 
1889a1d03eSRichard #define PROBLEMATIC_CONSTANT_UTF16_CHAR u'0'
1989a1d03eSRichard // CHECK-MESSAGES: [[@LINE-1]]:9: warning: macro 'PROBLEMATIC_CONSTANT_UTF16_CHAR' used to declare a constant; consider using a 'constexpr' constant
2089a1d03eSRichard 
2189a1d03eSRichard #define PROBLEMATIC_CONSTANT_UTF32_CHAR U'0'
2289a1d03eSRichard // CHECK-MESSAGES: [[@LINE-1]]:9: warning: macro 'PROBLEMATIC_CONSTANT_UTF32_CHAR' used to declare a constant; consider using a 'constexpr' constant
2389a1d03eSRichard 
2489a1d03eSRichard #define PROBLEMATIC_FUNCTION(x, y) ((a) > (b) ? (a) : (b))
2589a1d03eSRichard // CHECK-MESSAGES: [[@LINE-1]]:9: warning: function-like macro 'PROBLEMATIC_FUNCTION' used; consider a 'constexpr' template function
2689a1d03eSRichard 
2789a1d03eSRichard #define PROBLEMATIC_VARIADIC(...) (__VA_ARGS__)
2889a1d03eSRichard // CHECK-MESSAGES: [[@LINE-1]]:9: warning: variadic macro 'PROBLEMATIC_VARIADIC' used; consider using a 'constexpr' variadic template function
2989a1d03eSRichard 
3089a1d03eSRichard #define PROBLEMATIC_VARIADIC2(x, ...) (__VA_ARGS__)
3189a1d03eSRichard // CHECK-MESSAGES: [[@LINE-1]]:9: warning: variadic macro 'PROBLEMATIC_VARIADIC2' used; consider using a 'constexpr' variadic template function
3289a1d03eSRichard 
3389a1d03eSRichard // These are all examples of common macros that shouldn't have constexpr suggestions.
34*b06da39cSCongcong Cai #define CONCAT_NAME(a, b) a##b
35*b06da39cSCongcong Cai 
36*b06da39cSCongcong Cai #define CONCAT_STR(a, b) #a #b
37*b06da39cSCongcong Cai 
3889a1d03eSRichard #define COMMA ,
3989a1d03eSRichard 
4089a1d03eSRichard #define NORETURN [[noreturn]]
4189a1d03eSRichard 
4289a1d03eSRichard #define DEPRECATED attribute((deprecated))
4389a1d03eSRichard 
4489a1d03eSRichard #if LIB_EXPORTS
4589a1d03eSRichard #define DLLEXPORTS __declspec(dllexport)
4689a1d03eSRichard #else
4789a1d03eSRichard #define DLLEXPORTS __declspec(dllimport)
4889a1d03eSRichard #endif
4989a1d03eSRichard 
5089a1d03eSRichard #endif
51