Skip to content

Commit c2fc497

Browse files
Fix #10515 False positive for explicit one-argument constructor if co… (danmar#3718)
1 parent 9c56e7e commit c2fc497

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/symboldatabase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2208,7 +2208,7 @@ Function::Function(const Tokenizer *mTokenizer,
22082208
else
22092209
type = Function::eConstructor;
22102210

2211-
isExplicit(tokenDef->previous()->str() == "explicit");
2211+
isExplicit(tokenDef->strAt(-1) == "explicit" || tokenDef->strAt(-2) == "explicit");
22122212
}
22132213

22142214
const Token *tok1 = setFlags(tok, scope);

test/testclass.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,19 @@ class TestClass : public TestFixture {
444444
" A(int, int y=2) {}"
445445
"};");
446446
ASSERT_EQUALS("[test.cpp:1]: (style) Struct 'A' has a constructor with 1 argument that is not explicit.\n", errout.str());
447+
448+
checkExplicitConstructors("struct Foo {\n"
449+
" template <typename T>\n"
450+
" explicit constexpr Foo(T) {}\n"
451+
"};\n"
452+
"struct Bar {\n"
453+
" template <typename T>\n"
454+
" constexpr explicit Bar(T) {}\n"
455+
"};\n"
456+
"struct Baz {\n"
457+
" explicit constexpr Baz(int) {}\n"
458+
"};\n");
459+
ASSERT_EQUALS("", errout.str());
447460
}
448461

449462
#define checkDuplInheritedMembers(code) checkDuplInheritedMembers_(code, __FILE__, __LINE__)

0 commit comments

Comments
 (0)