From efb12f0409f5eee60ff7af8b4a86e2ba42626e96 Mon Sep 17 00:00:00 2001 From: Simon Martin Date: Sun, 15 Jun 2014 15:52:58 +0200 Subject: [PATCH] Ticket #5268: Properly detect function heads when in Tokenizer::simplifyEnum. --- lib/tokenize.cpp | 2 +- test/testtokenize.cpp | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 107aea5ea..18f357e34 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -7614,7 +7614,7 @@ void Tokenizer::simplifyEnum() const Token *prev = tok2->previous(); bool type = false; while (prev && (prev->isName() || Token::Match(prev, "*|&|::"))) { - type |= Token::Match(prev, "%type% !!::"); + type |= (Token::Match(prev, "%type% !!::") && !Token::Match(prev, "throw|return")); prev = prev->previous(); } if (type && (!prev || Token::Match(prev, "[;{}]"))) { diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index da41dd7fe..86d29cc79 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -197,6 +197,7 @@ private: TEST_CASE(simplifyKnownVariables55); // pointer alias TEST_CASE(simplifyKnownVariables56); // ticket #5301 - >> TEST_CASE(simplifyKnownVariables57); // ticket #4724 + TEST_CASE(simplifyKnownVariables58); // ticket #5268 TEST_CASE(simplifyKnownVariablesIfEq1); // if (a==5) => a is 5 in the block TEST_CASE(simplifyKnownVariablesIfEq2); // if (a==5) { buf[a++] = 0; } TEST_CASE(simplifyKnownVariablesIfEq3); // #4708 - if (a==5) { buf[--a] = 0; } @@ -2978,6 +2979,21 @@ private: ASSERT_EQUALS("long long x ; x = -9223372036854775808 ;", tokenizeAndStringify("long long x = 1L << 63 ;", true)); } + void simplifyKnownVariables58() { // #5268 + const char code[] = "enum e { VAL1 = 1, VAL2 }; " + "typedef char arr_t[VAL2]; " + "int foo(int) ; " + "void bar () { " + " throw foo (VAL1); " + "} " + "int baz() { " + " return sizeof(arr_t); " + "}"; + ASSERT_EQUALS("int foo ( int ) ; " + "void bar ( ) { throw foo ( 1 ) ; } " + "int baz ( ) { return 2 ; }", tokenizeAndStringify(code, true)); + } + void simplifyKnownVariablesIfEq1() { const char code[] = "void f(int x) {\n" " if (x==5) {\n"