Don't crash on `struct ::, struct ::` (and the same for enums).
authorLarisse Voufo <lvoufo@google.com>
Sun, 15 Feb 2015 08:47:30 +0000 (08:47 +0000)
committerLarisse Voufo <lvoufo@google.com>
Sun, 15 Feb 2015 08:47:30 +0000 (08:47 +0000)
commit1af89ed4267d7f31c8065a52a11900c51b2d2b88
tree91b7f08cd8cd8b12713f99645278d634952db942
parent0ddfe0c7c5a69d9894c8625b46426fddc9230aae
Don't crash on `struct ::, struct ::` (and the same for enums).

The first part of that line doesn't parse correctly and ParseClassSpecifier() for
some reason skips to tok::comma to recover, and then
ParseDeclarationSpecifiers() sees the next struct and calls
ParseClassSpecifier() again with the same DeclSpec object.

However, the first call already called ActOnCXXGlobalScopeSpecifier() on the
DeclSpec's CXXScopeSpec, and sema gets confused when this gets called again.

As a fix, let ParseClassSpecifier() (and ParseEnumSpecifier()) call
ParseOptionalCXXScopeSpec() with a temporary CXXScopeSpec object, and only
copy it into the DeclSpec if things work out.  (This is also how all the other
functions that set the DeclSpec's TypeSpecScope set it.)

Found by SLi's bot.

llvm-svn: 229293
clang/test/Parser/recovery.cpp