Skip to content

Commit 8aa568f

Browse files
Hinterwaeldlersdanmar
authored andcommitted
Corrected noexcept constructor delegating handling (danmar#948)
1 parent fc4f17d commit 8aa568f

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

lib/symboldatabase.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,9 +1176,18 @@ void SymbolDatabase::createSymbolDatabaseSetFunctionPointers(bool firstPass)
11761176
for (std::list<Scope>::iterator it = scopeList.begin(); it != scopeList.end(); ++it) {
11771177
for (std::list<Function>::const_iterator func = it->functionList.begin(); func != it->functionList.end(); ++func) {
11781178
// look for initializer list
1179-
if (func->type == Function::eConstructor && func->functionScope &&
1180-
func->functionScope->functionOf && func->arg && func->arg->link()->strAt(1) == ":") {
1181-
const Token * tok = func->arg->link()->tokAt(2);
1179+
if (func->type == Function::eConstructor && func->functionScope && func->functionScope->functionOf && func->arg) {
1180+
const Token * tok = func->arg->link()->next();
1181+
if (tok->str() == "noexcept") {
1182+
if (!tok->linkAt(1) || !tok->linkAt(1)->next()) {
1183+
continue;
1184+
}
1185+
tok = tok->linkAt(1)->next();
1186+
}
1187+
if (tok->str() != ":") {
1188+
continue;
1189+
}
1190+
tok = tok->next();
11821191
while (tok && tok != func->functionScope->classStart) {
11831192
if (Token::Match(tok, "%name% {|(")) {
11841193
if (tok->str() == func->tokenDef->str()) {

test/testconstructors.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,18 @@ class TestConstructors : public TestFixture {
10741074
"Foo::Foo() : Foo(0) {}\n"
10751075
"Foo::Foo(int foo) : foo_(foo) {}\n");
10761076
ASSERT_EQUALS("", errout.str());
1077+
1078+
// Noexcept ctors
1079+
check("class A {\n"
1080+
"private:\n"
1081+
" int _a;\n"
1082+
"public:\n"
1083+
" A(const int a) noexcept : _a{a} {}\n"
1084+
" A() noexcept;\n"
1085+
"};\n"
1086+
"\n"
1087+
"A::A() noexcept: A(0) {}");
1088+
ASSERT_EQUALS("", errout.str());
10771089
}
10781090

10791091

0 commit comments

Comments
 (0)