From: Richard Smith Date: Tue, 15 May 2012 21:29:55 +0000 (+0000) Subject: If we see a declaration which is either missing a type or has a malformed type, X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8f0a7e7845f619575f8af0b0bf46d027b20a0b63;p=clang If we see a declaration which is either missing a type or has a malformed type, and the thing we have has a scope specifier, and we're in a context that doesn't allow declaring a qualified name, then the error is a malformed type, not a missing type. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156856 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index dcc96cb861..36e3013701 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -1707,7 +1707,10 @@ bool Parser::ParseImplicitInt(DeclSpec &DS, CXXScopeSpec *SS, } } - if (DSC != DSC_type_specifier && DSC != DSC_trailing) { + // Determine whether this identifier could plausibly be the name of something + // being declared (with a missign type). + if (DSC != DSC_type_specifier && DSC != DSC_trailing && + (!SS || DSC == DSC_top_level || DSC == DSC_class)) { // Look ahead to the next token to try to figure out what this declaration // was supposed to be. switch (NextToken().getKind()) { diff --git a/test/SemaCXX/unknown-type-name.cpp b/test/SemaCXX/unknown-type-name.cpp index 5f8d8caae6..7912fbec3f 100644 --- a/test/SemaCXX/unknown-type-name.cpp +++ b/test/SemaCXX/unknown-type-name.cpp @@ -20,6 +20,8 @@ struct A { typedef T type; type f(); + + type g(); }; template @@ -27,3 +29,14 @@ A::type g(T t) { return t; } // expected-error{{missing 'typename'}} template A::type A::f() { return type(); } // expected-error{{missing 'typename'}} + +template +void f(int, T::type) { } // expected-error{{missing 'typename'}} + +template +void f(int, T::type, int) { } // expected-error{{missing 'typename'}} + +// FIXME: We know which type specifier should have been specified here. Provide +// a fix-it to add 'typename A::type' +template +A::g() { } // expected-error{{requires a type specifier}}