]> granicus.if.org Git - clang/commitdiff
Emit a specific diagnostic when typedefing C++ bool, mirroring gcc.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 16 Nov 2010 18:18:13 +0000 (18:18 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 16 Nov 2010 18:18:13 +0000 (18:18 +0000)
Fixes rdar://8365458

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

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

index bff6a38bcb76958ca774be9994f6af0174329047..ee0c5b326679eec70ddaa344134db3d25a63f1aa 100644 (file)
@@ -208,6 +208,8 @@ def err_expected_ident_in_using : Error<
   "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<
index 00788b0673b2ce8248ad63ddf93907cb7391d246..ed58a92323d98bb59fd307f33b236b55ba806360 100644 (file)
@@ -1348,8 +1348,16 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
       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,
index 6b355e814a8099605c4c2c80986efa57611018d5..6d720d36a259faacb7ec9619817deba1c05b786f 100644 (file)
@@ -6,6 +6,9 @@ struct Type {
   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 {