From 3f255e7685213e9aab2c9d3cd3056ab727a6b7f5 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Sun, 15 Nov 2015 14:37:02 +0100 Subject: [PATCH] Use Library information in Tokenizer::sizeOfType() --- lib/tokenize.cpp | 10 +++++++--- test/testsimplifytokens.cpp | 7 +++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 5dbf7899f..b8ee93a64 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -138,9 +138,13 @@ unsigned int Tokenizer::sizeOfType(const Token *type) const return Token::getStrLength(type) + 1U; std::map::const_iterator it = _typeSize.find(type->str()); - if (it == _typeSize.end()) - return 0; - else if (type->isLong()) { + if (it == _typeSize.end()) { + const Library::PodType* podtype = _settings->library.podtype(type->str()); + if (!podtype) + return 0; + + return podtype->size; + } else if (type->isLong()) { if (type->str() == "double") return _settings->sizeof_long_double; else if (type->str() == "long") diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index b647d1edc..927b27757 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -83,6 +83,7 @@ private: TEST_CASE(sizeof19); // #1891 - sizeof 'x' TEST_CASE(sizeof20); // #2024 - sizeof a) TEST_CASE(sizeof21); // #2232 - sizeof...(Args) + TEST_CASE(sizeof22); TEST_CASE(sizeofsizeof); TEST_CASE(casting); @@ -1396,6 +1397,12 @@ private: tok(code); } + void sizeof22() { + // sizeof from library + const char code[] = "foo(sizeof(uint32_t), sizeof(std::uint32_t));"; + TODO_ASSERT_EQUALS("foo ( 4 , 4 ) ;", "foo ( 4 , sizeof ( std :: uint32_t ) ) ;", tokWithStdLib(code)); + } + void sizeofsizeof() { // ticket #1682 const char code[] = "void f()\n"