forked from qt-creator/qt-creator
C++: Fix crashes with the pattern "enum class operator A"
Parser parsed the pattern as an enum declaration the name of which is a conversion operator. Add check to disallow keywords after enum-key (enum, enum class, enum struct). Add tests tst_AST::enumDeclaration and invalidEnumClassDeclaration. Task-number: QTCREATORBUG-15341 Change-Id: Ia037f00184c1d7e5b0374f39331bb6748f8d90b1 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
This commit is contained in:
committed by
Nikolai Kosjar
parent
c62ad6c450
commit
10e947f65f
5
src/libs/3rdparty/cplusplus/Parser.cpp
vendored
5
src/libs/3rdparty/cplusplus/Parser.cpp
vendored
@@ -1789,6 +1789,11 @@ bool Parser::parseEnumSpecifier(SpecifierListAST *&node)
|
|||||||
if (_languageFeatures.cxx11Enabled && (LA() == T_CLASS || LA() == T_STRUCT))
|
if (_languageFeatures.cxx11Enabled && (LA() == T_CLASS || LA() == T_STRUCT))
|
||||||
ast->key_token = consumeToken();
|
ast->key_token = consumeToken();
|
||||||
|
|
||||||
|
|
||||||
|
if (tok().isKeyword()) {
|
||||||
|
error(cursor(), "expected identifier before '%s'", tok().spell());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
parseName(ast->name);
|
parseName(ast->name);
|
||||||
|
|
||||||
if (_languageFeatures.cxx11Enabled && LA() == T_COLON) {
|
if (_languageFeatures.cxx11Enabled && LA() == T_COLON) {
|
||||||
|
@@ -208,6 +208,8 @@ private slots:
|
|||||||
void expensiveExpression();
|
void expensiveExpression();
|
||||||
void invalidCode_data();
|
void invalidCode_data();
|
||||||
void invalidCode();
|
void invalidCode();
|
||||||
|
void enumDeclaration();
|
||||||
|
void invalidEnumClassDeclaration();
|
||||||
};
|
};
|
||||||
|
|
||||||
void tst_AST::gcc_attributes_1()
|
void tst_AST::gcc_attributes_1()
|
||||||
@@ -1982,6 +1984,28 @@ void tst_AST::invalidCode()
|
|||||||
QVERIFY(diag.errorCount != 0);
|
QVERIFY(diag.errorCount != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_AST::enumDeclaration()
|
||||||
|
{
|
||||||
|
QSharedPointer<TranslationUnit> unit(parseStatement(
|
||||||
|
//Unnamed
|
||||||
|
"enum { ENUMERATOR0 };\n"
|
||||||
|
"enum Enum { ENUMERATOR1 };\n"
|
||||||
|
"enum EnumWithBase : int { ENUMERATOR2 };\n"
|
||||||
|
"enum enum : int { ENUMERATOR2a };\n"
|
||||||
|
"enum class EnumClass { ENUMERATOR3 = 10 };\n", true));
|
||||||
|
|
||||||
|
QVERIFY(unit->ast());
|
||||||
|
QCOMPARE(diag.errorCount, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_AST::invalidEnumClassDeclaration()
|
||||||
|
{
|
||||||
|
QSharedPointer<TranslationUnit> unit(parseStatement(
|
||||||
|
"enum class operator A { };", true));
|
||||||
|
|
||||||
|
QVERIFY(diag.errorCount != 0);
|
||||||
|
}
|
||||||
|
|
||||||
void tst_AST::initTestCase()
|
void tst_AST::initTestCase()
|
||||||
{
|
{
|
||||||
control.setDiagnosticClient(&diag);
|
control.setDiagnosticClient(&diag);
|
||||||
|
Reference in New Issue
Block a user