From 40f56e5b677761c8258324222d62fce3e4f6bca4 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Wed, 30 Jan 2013 23:10:17 +0000 Subject: [PATCH] Reinstate r173952, this time limiting it to exactly the form #define X X for which there is no point warning, ever. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173991 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Lex/PPMacroExpansion.cpp | 5 ++++- test/Headers/stdbool.cpp | 5 +++++ test/Preprocessor/warn-disabled-macro-expansion.c | 6 +++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/Lex/PPMacroExpansion.cpp b/lib/Lex/PPMacroExpansion.cpp index 6379144885..bda31ed294 100644 --- a/lib/Lex/PPMacroExpansion.cpp +++ b/lib/Lex/PPMacroExpansion.cpp @@ -459,7 +459,10 @@ bool Preprocessor::HandleMacroExpandedIdentifier(Token &Identifier, if (MacroInfo *NewMI = getMacroInfo(NewII)) if (!NewMI->isEnabled() || NewMI == MI) { Identifier.setFlag(Token::DisableExpand); - Diag(Identifier, diag::pp_disabled_macro_expansion); + // Don't warn for "#define X X" like "#define bool bool" from + // stdbool.h. + if (NewMI != MI || MI->isFunctionLike()) + Diag(Identifier, diag::pp_disabled_macro_expansion); } } diff --git a/test/Headers/stdbool.cpp b/test/Headers/stdbool.cpp index a252cca1a6..7c927db441 100644 --- a/test/Headers/stdbool.cpp +++ b/test/Headers/stdbool.cpp @@ -1,5 +1,6 @@ // RUN: %clang_cc1 -E -dM %s | FileCheck --check-prefix=CHECK-GNU-COMPAT %s // RUN: %clang_cc1 -std=c++98 -E -dM %s | FileCheck --check-prefix=CHECK-CONFORMING %s +// RUN: %clang_cc1 -fsyntax-only -std=gnu++98 -verify -Weverything %s #include #define zzz @@ -12,3 +13,7 @@ // CHECK-CONFORMING: #define __CHAR_BIT__ // CHECK-CONFORMING-NOT: #define false false // CHECK-CONFORMING: #define zzz + +zzz +// expected-no-diagnostics +extern bool x; diff --git a/test/Preprocessor/warn-disabled-macro-expansion.c b/test/Preprocessor/warn-disabled-macro-expansion.c index b01b63f6b3..21a3b7e4f1 100644 --- a/test/Preprocessor/warn-disabled-macro-expansion.c +++ b/test/Preprocessor/warn-disabled-macro-expansion.c @@ -14,9 +14,10 @@ #define c(x) x(0) +#define y(x) y #define z(x) (z)(x) -p // expected-warning {{recursive macro}} +p // no warning a // expected-warning {{recursive macro}} @@ -28,4 +29,7 @@ h(0) // expected-warning {{recursive macro}} c(c) // expected-warning {{recursive macro}} +y(5) // expected-warning {{recursive macro}} + z(z) // ok + -- 2.40.0