diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 0177265d2..689228f08 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3217,7 +3217,7 @@ bool Tokenizer::simplifySizeof() tok->deleteThis(); tok->deleteNext(); std::ostringstream sz; - sz << ((isC()) ? 4 : 1) ; // #7490 sizeof('a') should be 4 in C mode + sz << ((isC()) ? _settings->sizeof_int : 1) ; // #7490 sizeof('a') should be sizeof(int) in C mode tok->str(sz.str()); ret = true; continue; diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 7ceecfaf2..6b725b99e 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -23,7 +23,7 @@ #include "path.h" #include "preprocessor.h" // usually tests here should not use preprocessor... #include - +#include class TestTokenizer : public TestFixture { public: @@ -5878,7 +5878,9 @@ private: } void sizeOfCharLiteral() { // #7490 sizeof('a') should be 4 in C mode - ASSERT_EQUALS("unsigned long a ; a = 4 ;", + std::stringstream expected; + expected << "unsigned long a ; a = " << settings1.sizeof_int << " ;"; + ASSERT_EQUALS(expected.str(), 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));