From b940d0adc6842b1a8ff7c9243430b152823cfc12 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Fri, 9 Aug 2013 23:13:04 +0200 Subject: [PATCH] Fixed #4947 (Doesn't allow any ordering of int modifiers) --- lib/tokenize.cpp | 29 ++++++++++++++++++++++++++--- test/testtokenize.cpp | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 3 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 44f459b3e..b798d2be7 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -5565,18 +5565,41 @@ void Tokenizer::simplifyStdType() else if (tok->str() == "__int64") { tok->str("long"); tok->isLong(true); + } else if (tok->str() == "int") { + if (tok->strAt(1) == "long") { + tok->str("long"); + tok->deleteNext(); + } + if (tok->strAt(1) == "long") { + tok->isLong(true); + tok->deleteNext(); + } + if (tok->strAt(1) == "unsigned") { + tok->isUnsigned(true); + tok->deleteNext(); + if (tok->strAt(1) == "long") + tok->deleteNext(); + } } else if (tok->str() == "long") { if (tok->strAt(1) == "long") { tok->isLong(true); tok->deleteNext(); } - - if (tok->strAt(1) == "int") + if (tok->strAt(1) == "int") { tok->deleteNext(); - else if (tok->strAt(1) == "double") { + if (tok->strAt(1) == "unsigned") { + tok->isUnsigned(true); + tok->deleteNext(); + } + } else if (tok->strAt(1) == "double") { tok->str("double"); tok->isLong(true); tok->deleteNext(); + } else if (tok->strAt(1) == "unsigned") { + tok->isUnsigned(true); + tok->deleteNext(); + if (tok->strAt(1) == "int") + tok->deleteNext(); } } else if (tok->str() == "short") { if (tok->strAt(1) == "int") diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index dcbcaccaf..90a885dce 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -386,6 +386,8 @@ private: TEST_CASE(unsigned2); TEST_CASE(unsigned3); // template arguments + TEST_CASE(simplifyStdType); // #4947 + TEST_CASE(createLinks); TEST_CASE(signed1); @@ -6138,6 +6140,39 @@ private: } } + void simplifyStdType() { // #4947 + { + const char code[] = "long long unsigned int x;"; + const char expected[] = "unsigned long long x ;"; + ASSERT_EQUALS(expected, tokenizeAndStringify(code)); + } + { + const char code[] = "long long int unsigned x;"; + const char expected[] = "unsigned long long x ;"; + ASSERT_EQUALS(expected, tokenizeAndStringify(code)); + } + { + const char code[] = "unsigned long long int x;"; + const char expected[] = "unsigned long long x ;"; + ASSERT_EQUALS(expected, tokenizeAndStringify(code)); + } + { + const char code[] = "unsigned int long long x;"; + const char expected[] = "unsigned long long x ;"; + ASSERT_EQUALS(expected, tokenizeAndStringify(code)); + } + { + const char code[] = "int unsigned long long x;"; + const char expected[] = "unsigned long long x ;"; + ASSERT_EQUALS(expected, tokenizeAndStringify(code)); + } + { + const char code[] = "int long long unsigned x;"; + const char expected[] = "unsigned long long x ;"; + ASSERT_EQUALS(expected, tokenizeAndStringify(code)); + } + } + void createLinks() { { const char code[] = "class A{\n"