From 8b5792a0f8d2e8981a65b189bad930a6bb3d0c99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 4 Jun 2013 18:57:46 +0200 Subject: [PATCH] Tokenizer::simplifyEnum: Fixed internalErrors when building with compiled patterns. --- lib/tokenize.cpp | 15 ++++++++++++++- test/testsimplifytokens.cpp | 4 +++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 86b167057..50c149a3f 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -7439,6 +7439,10 @@ void Tokenizer::simplifyEnum() for (const Token* arg = tok2; arg && arg->str() != "("; arg = arg->previous()) { if (Token::Match(arg, "%type% [,)]") && enumValues.find(arg->str()) != enumValues.end()) { shadowArg.insert(arg->str()); + if (_settings->isEnabled("style")) { + const EnumValue enumValue = enumValues.find(arg->str())->second; + duplicateEnumError(arg, enumValue.name, "Function argument"); + } } } if (!shadowArg.empty()) { @@ -7455,8 +7459,17 @@ void Tokenizer::simplifyEnum() if (tok3->str() == "{") tok3 = tok3->link(); // skip inner scopes else if (tok3->isName() && enumValues.find(tok3->str()) != enumValues.end()) { - if (Token::Match(tok3->previous(), "*|%type%") || Token::Match(tok3->previous(), "& %type% =")) // variable declaration? + const Token *prev = tok3->previous(); + if ((prev->isName() && !Token::Match(prev, "return|case")) || + prev->str() == "*" || + Token::Match(prev, "& %type% =")) { + // variable declaration? shadowVars.insert(tok3->str()); + if (_settings->isEnabled("style")) { + const EnumValue enumValue = enumValues.find(tok3->str())->second; + duplicateEnumError(tok3, enumValue.name, "Variable"); + } + } } } if (!shadowVars.empty()) { diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index b0436bdab..7f306e9e9 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -7232,7 +7232,9 @@ private: " x+=1;\n" "}\n"; checkSimplifyEnum(code); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:1]: (style) Variable 'x' hides enumerator with same name\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:1]: (style) Variable 'x' hides enumerator with same name\n" + "[test.cpp:6] -> [test.cpp:1]: (style) Function argument 'x' hides enumerator with same name\n", + errout.str()); } void enum23() { // ticket #2804