File tree 4 files changed +14
-2
lines changed 4 files changed +14
-2
lines changed Original file line number Diff line number Diff line change 7
7
// ===----------------------------------------------------------------------===//
8
8
9
9
#include " MacroUsageCheck.h"
10
+ #include " clang/Basic/TokenKinds.h"
10
11
#include " clang/Frontend/CompilerInstance.h"
11
12
#include " clang/Lex/PPCallbacks.h"
12
13
#include " clang/Lex/Preprocessor.h"
13
14
#include " llvm/ADT/STLExtras.h"
14
15
#include " llvm/Support/Regex.h"
15
- #include < algorithm>
16
16
#include < cctype>
17
17
#include < functional>
18
18
@@ -37,7 +37,10 @@ class MacroUsageCallbacks : public PPCallbacks {
37
37
const MacroDirective *MD) override {
38
38
if (SM.isWrittenInBuiltinFile (MD->getLocation ()) ||
39
39
MD->getMacroInfo ()->isUsedForHeaderGuard () ||
40
- MD->getMacroInfo ()->getNumTokens () == 0 )
40
+ MD->getMacroInfo ()->tokens_empty () ||
41
+ llvm::any_of (MD->getMacroInfo ()->tokens (), [](const Token &T) {
42
+ return T.isOneOf (tok::TokenKind::hash, tok::TokenKind::hashhash);
43
+ }))
41
44
return ;
42
45
43
46
if (IgnoreCommandLineMacros &&
Original file line number Diff line number Diff line change @@ -266,6 +266,10 @@ Changes in existing checks
266
266
<clang-tidy/checks/bugprone/use-after-move>` check to also handle
267
267
calls to ``std::forward ``.
268
268
269
+ - Improved :doc: `cppcoreguidelines-macro-usage
270
+ <clang-tidy/checks/cppcoreguidelines/macro-usage>` check by ignoring macro with
271
+ hash preprocessing token.
272
+
269
273
- Improved :doc: `cppcoreguidelines-missing-std-forward
270
274
<clang-tidy/checks/cppcoreguidelines/missing-std-forward>` check by no longer
271
275
giving false positives for deleted functions, by fixing false negatives when only
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ Examples:
17
17
#define C 0
18
18
#define F1(x, y) ((a) > (b) ? (a) : (b))
19
19
#define F2(...) (__VA_ARGS__)
20
+ #define F3(x, y) x##y
20
21
#define COMMA ,
21
22
#define NORETURN [[noreturn]]
22
23
#define DEPRECATED attribute((deprecated))
Original file line number Diff line number Diff line change 31
31
// CHECK-MESSAGES: [[@LINE-1]]:9: warning: variadic macro 'PROBLEMATIC_VARIADIC2' used; consider using a 'constexpr' variadic template function
32
32
33
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
+
34
38
#define COMMA ,
35
39
36
40
#define NORETURN [[noreturn]]
You can’t perform that action at this time.
0 commit comments