Add test cases for assign operators with default implementation (#2767)

This commit is contained in:
Dan 2020-09-03 07:29:54 +02:00 committed by GitHub
parent 090eba7e7f
commit 974b6fb8e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View File

@ -2712,6 +2712,7 @@ void SymbolDatabase::addClassFunction(Scope **scope, const Token **tok, const To
const Token *closeParen = (*tok)->next()->link();
if (closeParen) {
if (Token::Match(closeParen, ") noexcept| = default ;") ||
Token::Match(closeParen, ") . const| %type% &| = default ;") ||
(Token::simpleMatch(closeParen, ") noexcept (") &&
Token::simpleMatch(closeParen->linkAt(2), ") = default ;"))) {
func->isDefault(true);

View File

@ -322,6 +322,7 @@ private:
TEST_CASE(symboldatabase83); // #9431
TEST_CASE(symboldatabase84);
TEST_CASE(symboldatabase85);
TEST_CASE(symboldatabase86);
TEST_CASE(createSymbolDatabaseFindAllScopes1);
@ -4610,6 +4611,15 @@ private:
ASSERT_EQUALS(std::intptr_t(vartok1->variable()), std::intptr_t(vartok2->variable()));
}
void symboldatabase86() {
GET_SYMBOL_DB("class C { auto operator=(const C&) -> C&; };\n"
"auto C::operator=(const C&) -> C& = default;");
ASSERT(db->scopeList.size() == 2);
ASSERT(db->scopeList.back().functionList.size() == 1);
ASSERT(db->scopeList.back().functionList.front().isDefault() == true);
ASSERT(db->scopeList.back().functionList.front().hasBody() == false);
}
void createSymbolDatabaseFindAllScopes1() {
GET_SYMBOL_DB("void f() { union {int x; char *p;} a={0}; }");
ASSERT(db->scopeList.size() == 3);