Skip to content

Commit 8320be2

Browse files
IOBYTEdanmar
authored andcommitted
Fixed cppcheck-opensource#8258 (Incorrect diagnostics when using delegating consturctor with default values) (cppcheck-opensource#1255)
1 parent 01cbadc commit 8320be2

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

‎lib/symboldatabase.cpp‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3963,6 +3963,9 @@ static void checkVariableCallMatch(const Variable* callarg, const Variable* func
39633963

39643964
static bool valueTypeMatch(const ValueType * valuetype, const Token * type)
39653965
{
3966+
if (valuetype->typeScope && type->type() && type->type()->classScope == valuetype->typeScope)
3967+
return true;
3968+
39663969
return ((((type->str() == "bool" && valuetype->type == ValueType::BOOL) ||
39673970
(type->str() == "char" && valuetype->type == ValueType::CHAR) ||
39683971
(type->str() == "short" && valuetype->type == ValueType::SHORT) ||
@@ -5321,6 +5324,14 @@ void SymbolDatabase::setValueTypeInTokenList()
53215324
setValueType(tok, valuetype);
53225325
}
53235326

5327+
// constructor
5328+
else if (tok->previous() && tok->previous()->type() && tok->previous()->type()->classScope) {
5329+
ValueType valuetype;
5330+
valuetype.type = ValueType::RECORD;
5331+
valuetype.typeScope = tok->previous()->type()->classScope;
5332+
setValueType(tok, valuetype);
5333+
}
5334+
53245335
// library function
53255336
else if (tok->previous()) {
53265337
const std::string& typestr(_settings->library.returnValueType(tok->previous()));

‎test/testconstructors.cpp‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,18 @@ class TestConstructors : public TestFixture {
10981098
" A(float a) : A(int(a)) {}\n"
10991099
"};");
11001100
ASSERT_EQUALS("", errout.str());
1101+
1102+
// Ticket #8258
1103+
check("struct F{};\n"
1104+
"struct Foo {\n"
1105+
" Foo(int a, F&& f, int b = 21) : _a(a), _b(b), _f(f) {}\n"
1106+
" Foo(int x, const char* value) : Foo(x, F(), 42) {}\n"
1107+
" Foo(int x, int* value) : Foo(x, F()) {}\n"
1108+
" int _a;\n"
1109+
" int _b;\n"
1110+
" F _f;\n"
1111+
"};");
1112+
ASSERT_EQUALS("", errout.str());
11011113
}
11021114

11031115

0 commit comments

Comments
 (0)