From 181879c293df6a88e8ef054c67c3b32beb5fc92c Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Wed, 12 Dec 2012 02:46:14 +0000 Subject: [PATCH] Don't warn about disabled macro expansion if we see the name of a function-like macro which isn't immediately followed by '('. FreeBSD's stdio.h #defines foo(x) to (foo)(x), apparently. llvm-svn: 169960 --- clang/lib/Lex/Preprocessor.cpp | 7 +++---- clang/test/Preprocessor/warn-disabled-macro-expansion.c | 4 ++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp index 4f0b189..df2c98d 100644 --- a/clang/lib/Lex/Preprocessor.cpp +++ b/clang/lib/Lex/Preprocessor.cpp @@ -592,9 +592,7 @@ void Preprocessor::HandleIdentifier(Token &Identifier) { // If this is a macro to be expanded, do it. if (MacroInfo *MI = getMacroInfo(&II)) { if (!DisableMacroExpansion) { - if (Identifier.isExpandDisabled()) { - Diag(Identifier, diag::pp_disabled_macro_expansion); - } else if (MI->isEnabled()) { + if (!Identifier.isExpandDisabled() && MI->isEnabled()) { if (!HandleMacroExpandedIdentifier(Identifier, MI)) return; } else { @@ -602,7 +600,8 @@ void Preprocessor::HandleIdentifier(Token &Identifier) { // expanded, even if it's in a context where it could be expanded in the // future. Identifier.setFlag(Token::DisableExpand); - Diag(Identifier, diag::pp_disabled_macro_expansion); + if (MI->isObjectLike() || isNextPPTokenLParen()) + Diag(Identifier, diag::pp_disabled_macro_expansion); } } } diff --git a/clang/test/Preprocessor/warn-disabled-macro-expansion.c b/clang/test/Preprocessor/warn-disabled-macro-expansion.c index fe8e90c7..b01b63f 100644 --- a/clang/test/Preprocessor/warn-disabled-macro-expansion.c +++ b/clang/test/Preprocessor/warn-disabled-macro-expansion.c @@ -14,6 +14,8 @@ #define c(x) x(0) +#define z(x) (z)(x) + p // expected-warning {{recursive macro}} a // expected-warning {{recursive macro}} @@ -25,3 +27,5 @@ g(3) // expected-warning {{recursive macro}} h(0) // expected-warning {{recursive macro}} c(c) // expected-warning {{recursive macro}} + +z(z) // ok -- 2.7.4