fix #9431 (Invalid syntax error on valid C++ code) (#2298)

This commit is contained in:
IOBYTE 2019-10-26 11:39:46 -04:00 committed by Daniel Marjamäki
parent 8fb794e731
commit 6b4a3bc830
2 changed files with 20 additions and 2 deletions

View File

@ -2397,7 +2397,7 @@ void SymbolDatabase::addClassFunction(Scope **scope, const Token **tok, const To
if (!func->hasBody()) {
const Token *closeParen = (*tok)->next()->link();
if (closeParen) {
if (Token::simpleMatch(closeParen, ") = default ;")) {
if (Token::Match(closeParen, ") noexcept| = default ;")) {
func->isDefault(true);
return;
}
@ -2469,7 +2469,7 @@ void SymbolDatabase::addClassFunction(Scope **scope, const Token **tok, const To
// normal function?
const Token *closeParen = (*tok)->next()->link();
if (closeParen) {
if (Token::simpleMatch(closeParen, ") = default ;")) {
if (Token::Match(closeParen, ") noexcept| = default ;")) {
func->isDefault(true);
return;
}

View File

@ -307,6 +307,7 @@ private:
TEST_CASE(symboldatabase80); // #9389
TEST_CASE(symboldatabase81); // #9411
TEST_CASE(symboldatabase82);
TEST_CASE(symboldatabase83); // #9431
TEST_CASE(createSymbolDatabaseFindAllScopes1);
@ -4423,6 +4424,23 @@ private:
ASSERT_EQUALS(false, db->functionScopes[0]->function->isConstructor());
}
void symboldatabase83() { // #9431
const bool old = settings1.debugwarnings;
settings1.debugwarnings = true;
GET_SYMBOL_DB("struct a { a() noexcept; };\n"
"a::a() noexcept = default;");
settings1.debugwarnings = old;
const Scope *scope = db->findScopeByName("a");
ASSERT(scope);
ASSERT(scope->functionList.size() == 1);
ASSERT(scope->functionList.front().name() == "a");
ASSERT(scope->functionList.front().hasBody() == false);
ASSERT(scope->functionList.front().isConstructor() == true);
ASSERT(scope->functionList.front().isDefault() == true);
ASSERT(scope->functionList.front().isNoExcept() == true);
ASSERT_EQUALS("", errout.str());
}
void createSymbolDatabaseFindAllScopes1() {
GET_SYMBOL_DB("void f() { union {int x; char *p;} a={0}; }");
ASSERT(db->scopeList.size() == 3);