* Add test for #9871

* Add test for #10144

* Format
This commit is contained in:
chrchr-github 2022-03-15 12:54:19 +01:00 committed by GitHub
parent 200b098471
commit f90a93591f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View File

@ -156,6 +156,7 @@ private:
TEST_CASE(duplicateExpression11); // #8916 (function call)
TEST_CASE(duplicateExpression12); // #10026
TEST_CASE(duplicateExpression13); // #7899
TEST_CASE(duplicateExpression14); // #9871
TEST_CASE(duplicateExpressionLoop);
TEST_CASE(duplicateValueTernary);
TEST_CASE(duplicateExpressionTernary); // #6391
@ -5592,6 +5593,16 @@ private:
ASSERT_EQUALS("", errout.str());
}
void duplicateExpression14() { //#9871
check("int f() {\n"
" int k = 7;\n"
" int* f = &k;\n"
" int* g = &k;\n"
" return (f + 4 != g + 4);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4] -> [test.cpp:5]: (style) The comparison 'f+4 != g+4' is always false because 'f+4' and 'g+4' represent the same value.\n", errout.str());
}
void duplicateExpressionLoop() {
check("void f() {\n"
" int a = 1;\n"

View File

@ -187,6 +187,7 @@ private:
TEST_CASE(simplifyTypedef138);
TEST_CASE(simplifyTypedef139);
TEST_CASE(simplifyTypedef140); // #10798
TEST_CASE(simplifyTypedef141); // #10144
TEST_CASE(simplifyTypedefFunction1);
TEST_CASE(simplifyTypedefFunction2); // ticket #1685
@ -3039,7 +3040,16 @@ private:
"enum class E { A };\n";
ASSERT_EQUALS("enum class E { A } ;", tok(code));
}
}
void simplifyTypedef141() { // #10144
const char code[] = "class C {\n"
" struct I {\n"
" using vt = const std::string;\n"
" using ptr = vt*;\n"
" };\n"
"};\n";
ASSERT_EQUALS("class C { struct I { } ; } ;", tok(code));
}
void simplifyTypedefFunction1() {