From 5658dfcaf355414b41a497ee6863e4e64a6265b5 Mon Sep 17 00:00:00 2001 From: IOBYTE Date: Fri, 18 Oct 2019 12:05:48 -0400 Subject: [PATCH] better fix for #9392 that also handles namespaces (#2282) --- lib/symboldatabase.cpp | 14 +++++++++----- test/testsymboldatabase.cpp | 22 +++++++++++++++++----- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index dec2d9914..c1bfd5403 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -2394,6 +2394,13 @@ void SymbolDatabase::addClassFunction(Scope **scope, const Token **tok, const To Function * func = findFunctionInScope(tok1, it2->scope, path, path_length); if (func) { if (!func->hasBody()) { + const Token *closeParen = (*tok)->next()->link(); + if (closeParen) { + if (Token::simpleMatch(closeParen, ") = default ;")) { + func->isDefault(true); + return; + } + } func->hasBody(true); func->token = *tok; func->arg = argStart; @@ -2461,11 +2468,8 @@ void SymbolDatabase::addClassFunction(Scope **scope, const Token **tok, const To // normal function? const Token *closeParen = (*tok)->next()->link(); if (closeParen) { - if (Token::Match(closeParen, ") = default|delete ;")) { - if (closeParen->strAt(2) == "default") - func->isDefault(true); - else - func->isDelete(true); + if (Token::simpleMatch(closeParen, ") = default ;")) { + func->isDefault(true); return; } diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index f9ad41596..73993120d 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -4284,11 +4284,23 @@ private: } void symboldatabase79() { // #9392 - GET_SYMBOL_DB("class C { C(); };\n" - "C::C() = default;"); - ASSERT(db->scopeList.size() == 2); - ASSERT(db->scopeList.back().functionList.size() == 1); - ASSERT(db->scopeList.back().functionList.front().isDefault() == true); + { + GET_SYMBOL_DB("class C { C(); };\n" + "C::C() = default;"); + ASSERT(db->scopeList.size() == 2); + ASSERT(db->scopeList.back().functionList.size() == 1); + ASSERT(db->scopeList.back().functionList.front().isDefault() == true); + } + { + GET_SYMBOL_DB("namespace ns {\n" + "class C { C(); };\n" + "}\n" + "using namespace ns;\n" + "C::C() = default;"); + ASSERT(db->scopeList.size() == 3); + ASSERT(db->scopeList.back().functionList.size() == 1); + ASSERT(db->scopeList.back().functionList.front().isDefault() == true); + } } void symboldatabase80() { // #9389