Parse: Recover better from bad definitions with base specifiers

We would skip until the next comma, hoping good things whould lie there,
however this would fail when we have such things as this:

struct A {};
template <typename>
struct D;
template <>
struct D<C> : B, A::D;

Once this happens, we would believe that D with a nested namespace
specifier of A was a variable that was being declared. We would go on
to complain that there was an extraneous 'template <>' on their variable
declaration.

Crashes would happen when 'A' gets defined as 'enum class A {}' as
various asserts would fire.

Instead, we should skip up until the semicolon if we see that we are in
the middle of a definition and the current token is a ':'

This fixes PR17084.

llvm-svn: 196453
This commit is contained in:
David Majnemer 2013-12-05 01:36:53 +00:00
parent 315133710d
commit 3252fd0d5b
2 changed files with 13 additions and 1 deletions

View File

@ -1429,7 +1429,13 @@ void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind,
<< DeclSpec::getSpecifierName(TagType);
}
SkipUntil(tok::comma, StopAtSemi);
// If we are parsing a definition and stop at a base-clause, continue on
// until the semicolon. Continuing from the comma will just trick us into
// thinking we are seeing a variable declaration.
if (TUK == Sema::TUK_Definition && Tok.is(tok::colon))
SkipUntil(tok::semi, StopBeforeMatch);
else
SkipUntil(tok::comma, StopAtSemi);
return;
}

View File

@ -129,3 +129,9 @@ NS::Foo<int> missingSemiBeforeFunctionReturningTemplateId1();
using NS::Foo;
struct MissingSemiThenTemplate2 {} // expected-error {{expected ';' after struct}}
Foo<int> missingSemiBeforeFunctionReturningTemplateId2();
namespace PR17084 {
enum class EnumID {};
template <typename> struct TempID;
template <> struct TempID<BadType> : BadType, EnumID::Garbage; // expected-error{{use of undeclared identifier 'BadType'}}
}