TestCharVar::pointer: Added one more test case to see that error message disappears when code is fixed

This commit is contained in:
Daniel Marjamäki 2011-07-05 19:57:07 +02:00
parent 8cd2c3115e
commit a1953f0964
1 changed files with 9 additions and 0 deletions

View File

@ -148,12 +148,21 @@ private:
void pointer() void pointer()
{ {
// ticket #2866
check("void f(char *p) {\n" check("void f(char *p) {\n"
" int ret = 0;\n" " int ret = 0;\n"
" ret |= *p;\n" " ret |= *p;\n"
" return ret;\n" " return ret;\n"
"}"); "}");
ASSERT_EQUALS("[test.cpp:2]: (warning) When using char variables in bit operations, sign extension can generate unexpected results.\n", errout.str()); ASSERT_EQUALS("[test.cpp:2]: (warning) When using char variables in bit operations, sign extension can generate unexpected results.\n", errout.str());
// fixed code
check("void f(char *p) {\n"
" int ret = 0;\n"
" ret |= (unsigned char)*p;\n"
" return ret;\n"
"}");
ASSERT_EQUALS("", errout.str());
} }
}; };