From 2299889f87978b8b09e5c8f2d554143f8892c45b Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Mon, 11 Jul 2011 20:39:47 +0000 Subject: [PATCH] Don't warn for unused macro when undef'ing it, if it comes from an included file. rdar://9745065 llvm-svn: 134919 --- clang/lib/Lex/PPDirectives.cpp | 2 +- clang/test/Preprocessor/warn-macro-unused.c | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index f74aad3c8164..efa188f75290 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -1594,7 +1594,7 @@ void Preprocessor::HandleUndefDirective(Token &UndefTok) { // If the macro is not defined, this is a noop undef, just return. if (MI == 0) return; - if (!MI->isUsed()) + if (!MI->isUsed() && MI->isWarnIfUnused()) Diag(MI->getDefinitionLoc(), diag::pp_macro_not_used); // If the callbacks want to know, tell them about the macro #undef. diff --git a/clang/test/Preprocessor/warn-macro-unused.c b/clang/test/Preprocessor/warn-macro-unused.c index 8a6d7c25ca5f..c33aeb5df9d9 100644 --- a/clang/test/Preprocessor/warn-macro-unused.c +++ b/clang/test/Preprocessor/warn-macro-unused.c @@ -1,5 +1,10 @@ // RUN: %clang_cc1 %s -Wunused-macros -Dfoo -Dfoo -verify +#include "warn-macro-unused.h" + #define unused // expected-warning {{macro is not used}} #define unused unused + +// rdar://9745065 +#undef unused_from_header // no warning