Added regression test for #8332.

This commit is contained in:
orbitcowboy 2022-04-06 08:12:41 +02:00
parent 4fde7f8b18
commit 64a7ba3c4c
1 changed files with 10 additions and 0 deletions

View File

@ -134,6 +134,16 @@ private:
" abc[0] = 'a';\n"
"}");
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2]: (error) Modifying string literal u\"abc\" directly or indirectly is undefined behaviour.\n", errout.str());
check("void foo() {\n" // #8332
" int i;\n"
" char *p = \"string literal\";\n"
" for( i = 0; i < strlen(p); i++) {\n"
" p[i] = \'X\';\n" // <<
" }\n"
" printf(\"%s\\n\", p);\n"
"}");
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (error) Modifying string literal \"string literal\" directly or indirectly is undefined behaviour.\n", errout.str());
}
void alwaysTrueFalseStringCompare() {