From: David Blaikie Date: Tue, 25 Oct 2011 18:46:41 +0000 (+0000) Subject: Handle redundant 'typename' on base class specifications. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7fe3878a36750515fb9772414ecb2489cf149d19;p=clang Handle redundant 'typename' on base class specifications. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142937 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticParseKinds.td b/include/clang/Basic/DiagnosticParseKinds.td index f8b54400e0..e0b10fa87c 100644 --- a/include/clang/Basic/DiagnosticParseKinds.td +++ b/include/clang/Basic/DiagnosticParseKinds.td @@ -252,6 +252,8 @@ def err_unexpected_typedef_ident : Error< def err_unexpected_scope_on_base_decltype : Error< "unexpected namespace scope prior to decltype">; def err_expected_class_name : Error<"expected class name">; +def err_expected_class_name_not_template : + Error<"'typename' is redundant; base classes are implicitly types">; def err_unspecified_vla_size_with_static : Error< "'static' may not be used with an unspecified variable length array size">; diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp index 8530ff2740..1ba1cbfbd6 100644 --- a/lib/Parse/ParseDeclCXX.cpp +++ b/lib/Parse/ParseDeclCXX.cpp @@ -713,6 +713,13 @@ void Parser::ParseUnderlyingTypeSpecifier(DeclSpec &DS) { /// Parser::TypeResult Parser::ParseBaseTypeSpecifier(SourceLocation &BaseLoc, SourceLocation &EndLocation) { + // Ignore attempts to use typename + if (Tok.is(tok::kw_typename)) { + Diag(Tok, diag::err_expected_class_name_not_template) + << FixItHint::CreateRemoval(Tok.getLocation()); + ConsumeToken(); + } + // Parse optional nested-name-specifier CXXScopeSpec SS; ParseOptionalCXXScopeSpecifier(SS, ParsedType(), /*EnteringContext=*/false); diff --git a/test/CXX/class.derived/p1.cpp b/test/CXX/class.derived/p1.cpp index d819ea2389..dc5cb2b8c2 100644 --- a/test/CXX/class.derived/p1.cpp +++ b/test/CXX/class.derived/p1.cpp @@ -34,4 +34,7 @@ namespace PR11216 { struct Derived4 : :: decltype(Base()) { }; // expected-error {{unexpected namespace scope prior to decltype}} struct Derived5 : PR11216:: decltype(Base()) { }; // expected-error {{unexpected namespace scope prior to decltype}} + + template + struct Derived6 : typename T::foo { }; // expected-error {{'typename' is redundant; base classes are implicitly types}} }