From 9d1302d523dc52d7ccc9e480b69bf2c7b3494b10 Mon Sep 17 00:00:00 2001 From: Alexander Mai Date: Sat, 14 May 2016 22:52:43 +0200 Subject: [PATCH] #7490 sizeof('a') should be sizeof(int) in C mode. Previous fix was hardcoding 4 for C. --- lib/tokenize.cpp | 2 +- test/testtokenize.cpp | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) 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));