Fix in Tokenizer::simplifyUsing for non-scopes

This commit is contained in:
Daniel Marjamäki 2021-08-21 10:10:40 +02:00
parent 96196875b4
commit ca50dea97d
3 changed files with 17 additions and 4 deletions

View File

@ -9,7 +9,6 @@ bitwiseOnBoolean
unusedPrivateFunction:test/test*.cpp unusedPrivateFunction:test/test*.cpp
useStlAlgorithm useStlAlgorithm
simplifyUsing:lib/valueptr.h simplifyUsing:lib/valueptr.h
simplifyUsingUnmatchedBodyEnd
# debug suppressions # debug suppressions
valueFlowBailout valueFlowBailout

View File

@ -1915,11 +1915,12 @@ namespace {
ScopeInfo3 *parent = (*scopeInfo)->parent; ScopeInfo3 *parent = (*scopeInfo)->parent;
while (parent && parent->bodyEnd != tok) while (parent && parent->bodyEnd != tok)
parent = parent->parent; parent = parent->parent;
if (parent) if (parent) {
*scopeInfo = parent; *scopeInfo = parent;
if (debug) if (debug)
throw std::runtime_error("Internal error: unmatched }"); throw std::runtime_error("Internal error: unmatched }");
} }
}
return; return;
} }
if (!Token::Match(tok, "namespace|class|struct|union %name% {|:|::|<")) { if (!Token::Match(tok, "namespace|class|struct|union %name% {|:|::|<")) {

View File

@ -92,6 +92,7 @@ private:
TEST_CASE(simplifyUsing10335); TEST_CASE(simplifyUsing10335);
TEST_CASE(scopeInfo1); TEST_CASE(scopeInfo1);
TEST_CASE(scopeInfo2);
} }
std::string tok(const char code[], bool simplify = true, Settings::PlatformType type = Settings::Native, bool debugwarnings = true) { std::string tok(const char code[], bool simplify = true, Settings::PlatformType type = Settings::Native, bool debugwarnings = true) {
@ -1324,6 +1325,18 @@ private:
tok(code, true); tok(code, true);
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void scopeInfo2() {
const char code[] = "struct A {\n"
" using Map = std::map<int, int>;\n"
" Map values;\n"
"};\n"
"\n"
"static void getInitialProgramState(const A::Map& vars = A::Map {})\n"
"{}\n";
tok(code, true);
ASSERT_EQUALS("", errout.str());
}
}; };
REGISTER_TEST(TestSimplifyUsing) REGISTER_TEST(TestSimplifyUsing)