diff options
| author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-01-18 19:50:15 +0000 |
|---|---|---|
| committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-01-18 19:50:15 +0000 |
| commit | b495cc1a7ba585f869d4f5cfc248047c213df1be (patch) | |
| tree | 71f355c1eba190e4b43f80aab53c5000dc00819e | |
| parent | b02a9dfa55cc617a5dc2c05fcee1601c57ba4c95 (diff) | |
| download | bcm5719-llvm-b495cc1a7ba585f869d4f5cfc248047c213df1be.tar.gz bcm5719-llvm-b495cc1a7ba585f869d4f5cfc248047c213df1be.zip | |
When redefining a macro don't warn twice if it's not used and don't warn for duplicate
definition by command line options. Fixes rdar://8875916.
llvm-svn: 123767
| -rw-r--r-- | clang/lib/Lex/PPDirectives.cpp | 4 | ||||
| -rw-r--r-- | clang/test/Preprocessor/warn-macro-unused.c | 5 |
2 files changed, 8 insertions, 1 deletions
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index f422d254f0f..0f0d25b887a 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -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/clang/test/Preprocessor/warn-macro-unused.c b/clang/test/Preprocessor/warn-macro-unused.c new file mode 100644 index 00000000000..8a6d7c25ca5 --- /dev/null +++ b/clang/test/Preprocessor/warn-macro-unused.c @@ -0,0 +1,5 @@ +// RUN: %clang_cc1 %s -Wunused-macros -Dfoo -Dfoo -verify + +#define unused // expected-warning {{macro is not used}} +#define unused +unused |

