#7490 sizeof('a') should be 4 in C mode

This commit is contained in:
Alexander Mai 2016-05-14 13:05:44 +02:00
parent 60efae147f
commit 251fc022fa
2 changed files with 9 additions and 1 deletions

View File

@ -3215,7 +3215,7 @@ bool Tokenizer::simplifySizeof()
tok->deleteThis();
tok->deleteNext();
std::ostringstream sz;
sz << sizeof 'x';
sz << ((isC()) ? 4 : 1) ; // #7490 sizeof('a') should be 4 in C mode
tok->str(sz.str());
ret = true;
continue;

View File

@ -388,6 +388,7 @@ private:
// a = b = 0;
TEST_CASE(multipleAssignment);
TEST_CASE(sizeOfCharLiteral);
TEST_CASE(platformWin);
TEST_CASE(platformWin32);
TEST_CASE(platformWin32A);
@ -5865,6 +5866,13 @@ private:
ASSERT_EQUALS("a = b = 0 ;", tokenizeAndStringify("a=b=0;"));
}
void sizeOfCharLiteral() { // #7490 sizeof('a') should be 4 in C mode
ASSERT_EQUALS("unsigned long a ; a = 4 ;",
tokenizeAndStringify("unsigned long a = sizeof('x');", true, true, Settings::Native, "test.c", false));
ASSERT_EQUALS("unsigned long a ; a = 1 ;",
tokenizeAndStringify("unsigned long a = sizeof('x');", true, true, Settings::Native, "test.cpp", true));
}
void platformWin() {
const char code[] = "BOOL f;"
"BOOLEAN g;"