Improve duplicateExpressionTernary (#2484)

Test both the cases where sizeof(int) == sizeof(long) and when they are
different to improve testing.
This commit is contained in:
Rikard Falkeborn 2020-01-10 10:02:50 +01:00 committed by amai2012
parent fcd5cda97f
commit 9afeef01c6
1 changed files with 18 additions and 4 deletions

View File

@ -4846,10 +4846,24 @@ private:
ASSERT_EQUALS("", errout.str());
// #6426
check("void foo(bool flag) {\n"
{
const char code[] = "void foo(bool flag) {\n"
" bar( (flag) ? ~0u : ~0ul);\n"
"}");
ASSERT_EQUALS((_settings.sizeof_int==_settings.sizeof_long)?"[test.cpp:2]: (style) Same value in both branches of ternary operator.\n":"", errout.str());
"}";
Settings settings = _settings;
settings.sizeof_int = 4;
settings.int_bit = 32;
settings.sizeof_long = 4;
settings.long_bit = 32;
check(code, &settings);
ASSERT_EQUALS("[test.cpp:2]: (style) Same value in both branches of ternary operator.\n", errout.str());
settings.sizeof_long = 8;
settings.long_bit = 64;
check(code, &settings);
ASSERT_EQUALS("", errout.str());
}
}
void duplicateValueTernary() {