diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2010-11-16 18:18:13 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2010-11-16 18:18:13 +0000 |
commit | 4383e18fc3d79fd536c6992432e180a11bcb657d (patch) | |
tree | 97c8fe80e695f54c1ef03ad6d44712dae74f4cbe | |
parent | e645c72d1eceb170cd157fc3c725ebf95a74c439 (diff) |
Emit a specific diagnostic when typedefing C++ bool, mirroring gcc.
Fixes rdar://8365458
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@119359 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Basic/DiagnosticParseKinds.td | 2 | ||||
-rw-r--r-- | lib/Parse/ParseDecl.cpp | 12 | ||||
-rw-r--r-- | test/Parser/cxx-decl.cpp | 3 |
3 files changed, 15 insertions, 2 deletions
diff --git a/include/clang/Basic/DiagnosticParseKinds.td b/include/clang/Basic/DiagnosticParseKinds.td index bff6a38bcb..ee0c5b3266 100644 --- a/include/clang/Basic/DiagnosticParseKinds.td +++ b/include/clang/Basic/DiagnosticParseKinds.td @@ -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< diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 00788b0673..ed58a92323 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -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, diff --git a/test/Parser/cxx-decl.cpp b/test/Parser/cxx-decl.cpp index 6b355e814a..6d720d36a2 100644 --- a/test/Parser/cxx-decl.cpp +++ b/test/Parser/cxx-decl.cpp @@ -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 { |