// __null is usually wrapped in a macro. Go up a macro if that is the case.
if (NullKind == Expr::NPCK_GNUNull) {
- if (Loc.isMacroID())
- Loc = S.SourceMgr.getImmediateExpansionRange(Loc).first;
+ if (Loc.isMacroID()) {
+ StringRef MacroName =
+ Lexer::getImmediateMacroName(Loc, S.SourceMgr, S.getLangOpts());
+ if (MacroName == "NULL")
+ Loc = S.SourceMgr.getImmediateExpansionRange(Loc).first;
+ }
}
// Only warn if the null and context location are in the same macro expansion.
return EXIT();
}
}
+
+// Test NULL macro inside a macro has same warnings nullptr inside a macro.
+namespace test10 {
+#define test1(cond) \
+ ((cond) ? nullptr : NULL)
+#define test2(cond) \
+ ((cond) ? NULL : nullptr)
+
+#define assert(cond) \
+ ((cond) ? foo() : bar())
+ void foo();
+ void bar();
+
+ void run(int x) {
+ if (test1(x)) {}
+ if (test2(x)) {}
+ assert(test1(x));
+ assert(test2(x));
+ }
+}