]> granicus.if.org Git - clang/commitdiff
When redefining a macro don't warn twice if it's not used and don't warn for duplicate
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 18 Jan 2011 19:50:15 +0000 (19:50 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 18 Jan 2011 19:50:15 +0000 (19:50 +0000)
definition by command line options. Fixes rdar://8875916.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123767 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Lex/PPDirectives.cpp
test/Preprocessor/warn-macro-unused.c [new file with mode: 0644]

index f422d254f0f20f0641a9466915f851a55b3d9f27..0f0d25b887afc966299195025f6db2ad1af16b7a 100644 (file)
@@ -1527,7 +1527,7 @@ void Preprocessor::HandleDefineDirective(Token &DefineTok) {
     // then don't bother calling MacroInfo::isIdenticalTo.
     if (!getDiagnostics().getSuppressSystemWarnings() ||
         !SourceMgr.isInSystemHeader(DefineTok.getLocation())) {
-      if (!OtherMI->isUsed())
+      if (!OtherMI->isUsed() && OtherMI->isWarnIfUnused())
         Diag(OtherMI->getDefinitionLoc(), diag::pp_macro_not_used);
 
       // Macros must be identical.  This means all tokens and whitespace
@@ -1539,6 +1539,8 @@ void Preprocessor::HandleDefineDirective(Token &DefineTok) {
         Diag(OtherMI->getDefinitionLoc(), diag::note_previous_definition);
       }
     }
+    if (OtherMI->isWarnIfUnused())
+      WarnUnusedMacroLocs.erase(OtherMI->getDefinitionLoc());
     ReleaseMacroInfo(OtherMI);
   }
 
diff --git a/test/Preprocessor/warn-macro-unused.c b/test/Preprocessor/warn-macro-unused.c
new file mode 100644 (file)
index 0000000..8a6d7c2
--- /dev/null
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 %s -Wunused-macros -Dfoo -Dfoo -verify
+
+#define unused // expected-warning {{macro is not used}}
+#define unused
+unused