[cfe-commits] r119359 - in /cfe/trunk: include/clang/Basic/DiagnosticParseKinds.td lib/Parse/ParseDecl.cpp test/Parser/cxx-decl.cpp

Argyrios Kyrtzidis akyrtzi at gmail.com
Tue Nov 16 10:18:13 PST 2010


Author: akirtzidis
Date: Tue Nov 16 12:18:13 2010
New Revision: 119359

URL: http://llvm.org/viewvc/llvm-project?rev=119359&view=rev
Log:
Emit a specific diagnostic when typedefing C++ bool, mirroring gcc.
Fixes rdar://8365458

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
    cfe/trunk/lib/Parse/ParseDecl.cpp
    cfe/trunk/test/Parser/cxx-decl.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=119359&r1=119358&r2=119359&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Tue Nov 16 12:18:13 2010
@@ -208,6 +208,8 @@
   "expected an identifier in using directive">;
 def err_unexected_colon_in_nested_name_spec : Error<
   "unexpected ':' in nested name specifier">;
+def err_bool_redeclaration : Error<
+  "redeclaration of C++ built-in type 'bool'">;
 
 /// Objective-C parser diagnostics
 def err_expected_minus_or_plus : Error<

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=119359&r1=119358&r2=119359&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Tue Nov 16 12:18:13 2010
@@ -1348,8 +1348,16 @@
       break;
     case tok::kw_bool:
     case tok::kw__Bool:
-      isInvalid = DS.SetTypeSpecType(DeclSpec::TST_bool, Loc, PrevSpec,
-                                     DiagID);
+      if (Tok.is(tok::kw_bool) &&
+          DS.getTypeSpecType() != DeclSpec::TST_unspecified &&
+          DS.getStorageClassSpec() == DeclSpec::SCS_typedef) {
+        PrevSpec = ""; // Not used by the diagnostic.
+        DiagID = diag::err_bool_redeclaration;
+        isInvalid = true;
+      } else {
+        isInvalid = DS.SetTypeSpecType(DeclSpec::TST_bool, Loc, PrevSpec,
+                                       DiagID);
+      }
       break;
     case tok::kw__Decimal32:
       isInvalid = DS.SetTypeSpecType(DeclSpec::TST_decimal32, Loc, PrevSpec,

Modified: cfe/trunk/test/Parser/cxx-decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx-decl.cpp?rev=119359&r1=119358&r2=119359&view=diff
==============================================================================
--- cfe/trunk/test/Parser/cxx-decl.cpp (original)
+++ cfe/trunk/test/Parser/cxx-decl.cpp Tue Nov 16 12:18:13 2010
@@ -6,6 +6,9 @@
   int Type;
 };
 
+// rdar://8365458
+typedef char bool; // expected-error {{redeclaration of C++ built-in type 'bool'}} \
+                   // expected-warning {{declaration does not declare anything}}
 
 // PR4451 - We should recover well from the typo of '::' as ':' in a2.
 namespace y {





More information about the cfe-commits mailing list