]> granicus.if.org Git - clang/commitdiff
[preprocessor] Don't warn about "disabled expansion of recursive macro"
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 30 Jan 2013 18:55:52 +0000 (18:55 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 30 Jan 2013 18:55:52 +0000 (18:55 +0000)
for "#define X X".

This is a pattern that, for example, stdbool.h uses.
rdar://12435773

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

lib/Lex/PPMacroExpansion.cpp
test/Headers/stdbool.cpp
test/Preprocessor/warn-disabled-macro-expansion.c

index 63791448858e373277c8f9e71aff0ae75f439e43..939c4faf7a057fce7a9545f8cda9762de67b8798 100644 (file)
@@ -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)
+            Diag(Identifier, diag::pp_disabled_macro_expansion);
         }
     }
 
index a252cca1a6a753a19e2b7253f7007353759f402d..7c927db441b2bc5c097758ade6a3517604ce438a 100644 (file)
@@ -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 <stdbool.h>
 #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;
index b01b63f6b3f7823f498a6a08cc3fe38dfad79fb3..c97a4ee4431e00250b08ead3df08007a7cb948c9 100644 (file)
@@ -16,7 +16,7 @@
 
 #define z(x) (z)(x)
 
-p // expected-warning {{recursive macro}}
+p // no warning
 
 a // expected-warning {{recursive macro}}