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 COMMA ,
35
36#define NORETURN [[noreturn]]
37
38#define DEPRECATED attribute((deprecated))
39
40#if LIB_EXPORTS
41#define DLLEXPORTS __declspec(dllexport)
42#else
43#define DLLEXPORTS __declspec(dllimport)
44#endif
45
46#endif
47

source code of clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/macro-usage.cpp