[clang-tools-extra] `cppcoreguidelines-macro-usage`: Skip common macros which cannot be converted to `constexpr` (PR #80797)
Piotr Zegar via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 6 12:01:42 PST 2024
================
@@ -80,6 +80,20 @@ void MacroUsageCheck::warnMacro(const MacroDirective *MD, StringRef MacroName) {
const MacroInfo *Info = MD->getMacroInfo();
StringRef Message;
+ for (const auto &T : MD->getMacroInfo()->tokens()) {
+ if (T.is(tok::hash)) {
+ return;
+ }
+ if (T.is(tok::identifier)) {
+ StringRef IdentName = T.getIdentifierInfo()->getName();
+ if (IdentName == "__FILE__") {
+ return;
+ } else if (IdentName == "__LINE__") {
+ return;
+ }
+ }
+ }
+
----------------
PiotrZSL wrote:
Yes, probably easiest option would be simply to add config option like IgnoreMacrosThatUse, or something similar, make it regexp, and then add release note entry that "Macros that use directly an built-in macros are ignored". If you dont want to make that option public, it's fine, it can be some global static vector with strings in a check. Just to avoid bunch of ifs....
https://github.com/llvm/llvm-project/pull/80797
More information about the cfe-commits
mailing list