Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions addons/test/misra/misra-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -645,11 +645,11 @@ static void misra_10_1_ternary(void)

a = ui16 << ui16; // 10.6
a = ui16 << (get_bool(42) ? ui16 : ui16);
a = ui16 << (get_bool(42) ? ui16 : (get_bool(34) ? ui16 : ui16)); // 10.4
a = ui16 << (get_bool(42) ? (get_bool(34) ? ui16 : ui16) : ui16); // 10.4
a = ui16 << (get_bool(42) ? i16 : (get_bool(34) ? ui16 : ui16)); // 10.1
a = ui16 << (get_bool(42) ? ui16 : (get_bool(34) ? ui16 : ui16));
a = ui16 << (get_bool(42) ? (get_bool(34) ? ui16 : ui16) : ui16);
a = ui16 << (get_bool(42) ? i16 : (get_bool(34) ? ui16 : ui16)); // 10.1 10.4
a = ui16 << (get_bool(42) ? (get_bool(34) ? ui16 : i16) : ui16); // 10.1 10.4
a = ui16 << (get_bool(42) ? (get_bool(34) ? ui16 : ui16) : i16); // 10.1
a = ui16 << (get_bool(42) ? (get_bool(34) ? ui16 : ui16) : i16); // 10.1 10.4
a = ui16 << (get_bool(42) ? (get_bool(34) ? ui16 : ui8) : ui8); // 10.4
a = ui16 << (get_bool(42) ? (get_bool(34) ? i16 : ui8) : ui8); // 10.1 10.4
a = (get_bool(42) ? (get_bool(34) ? ui16 : ui8) : ui8) << ui16; // 10.4
Expand Down Expand Up @@ -1171,7 +1171,7 @@ static void misra_14_2_fn1(bool b) {
g += 2;
i2 ^= 2; // 14.2
if (i2 == 2) {
g += g_arr[i2];
g += g_arr[i2]; // cppcheck-suppress legacyUninitvar
}
misra_14_2_init_value(&i2); // TODO: Fix false negative in function call
}
Expand Down
5 changes: 5 additions & 0 deletions lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6552,6 +6552,11 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, Source
setValueType(parent, *vt1);
return;
}

if (vt1->isTypeEqual(vt2)) {
setValueType(parent, *vt1);
return;
}
}

if (vt1->pointer != 0U) {
Expand Down
22 changes: 19 additions & 3 deletions test/testsymboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ class TestSymbolDatabase : public TestFixture {
TEST_CASE(auto18);
TEST_CASE(auto19);
TEST_CASE(auto20);
TEST_CASE(auto21);

TEST_CASE(unionWithConstructor);

Expand Down Expand Up @@ -5716,8 +5717,7 @@ class TestSymbolDatabase : public TestFixture {
ASSERT_EQUALS(E1->value, 1);
const Token* const a = Token::findsimplematch(tokenizer.tokens(), "auto");
ASSERT(a && a->valueType());
TODO_ASSERT(E1->scope == a->valueType()->typeScope);
ASSERT_EQUALS(a->valueType()->type, ValueType::INT);
ASSERT(E1->scope == a->valueType()->typeScope);
}

void sizeOfType() {
Expand Down Expand Up @@ -9399,7 +9399,6 @@ class TestSymbolDatabase : public TestFixture {
ASSERT(autoTok && autoTok->valueType());
ASSERT_EQUALS(autoTok->valueType()->constness, 3);
ASSERT_EQUALS(autoTok->valueType()->pointer, 1);
TODO_ASSERT(autoTok->valueType()->reference == Reference::LValue);
}

void auto19() { // #11517
Expand Down Expand Up @@ -9454,6 +9453,23 @@ class TestSymbolDatabase : public TestFixture {
ASSERT_EQUALS(g->function()->tokenDef->linenr(), 4);
}

void auto21() {
GET_SYMBOL_DB("int f(bool b) {\n"
" std::vector<int> v1(1), v2(2);\n"
" auto& v = b ? v1 : v2;\n"
" v.push_back(1);\n"
" return v.size();\n"
"}\n");
ASSERT_EQUALS("", errout.str());
const Token* a = Token::findsimplematch(tokenizer.tokens(), "auto");
ASSERT(a && a->valueType());
ASSERT_EQUALS(a->valueType()->type, ValueType::CONTAINER);
const Token* v = Token::findsimplematch(a, "v . size");
ASSERT(v && v->valueType());
ASSERT_EQUALS(v->valueType()->type, ValueType::CONTAINER);
ASSERT(v->variable() && v->variable()->isReference());
}

void unionWithConstructor() {
GET_SYMBOL_DB("union Fred {\n"
" Fred(int x) : i(x) { }\n"
Expand Down