Fix #10515 False positive for explicit one-argument constructor if co… (#3718)

This commit is contained in:
chrchr-github 2022-01-17 20:51:23 +01:00 committed by GitHub
parent 9c56e7ea8d
commit c2fc4973ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -2208,7 +2208,7 @@ Function::Function(const Tokenizer *mTokenizer,
else
type = Function::eConstructor;
isExplicit(tokenDef->previous()->str() == "explicit");
isExplicit(tokenDef->strAt(-1) == "explicit" || tokenDef->strAt(-2) == "explicit");
}
const Token *tok1 = setFlags(tok, scope);

View File

@ -444,6 +444,19 @@ private:
" A(int, int y=2) {}"
"};");
ASSERT_EQUALS("[test.cpp:1]: (style) Struct 'A' has a constructor with 1 argument that is not explicit.\n", errout.str());
checkExplicitConstructors("struct Foo {\n"
" template <typename T>\n"
" explicit constexpr Foo(T) {}\n"
"};\n"
"struct Bar {\n"
" template <typename T>\n"
" constexpr explicit Bar(T) {}\n"
"};\n"
"struct Baz {\n"
" explicit constexpr Baz(int) {}\n"
"};\n");
ASSERT_EQUALS("", errout.str());
}
#define checkDuplInheritedMembers(code) checkDuplInheritedMembers_(code, __FILE__, __LINE__)