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
useStlAlgorithm
simplifyUsing:lib/valueptr.h
simplifyUsingUnmatchedBodyEnd
# debug suppressions
valueFlowBailout

View File

@ -1915,10 +1915,11 @@ namespace {
ScopeInfo3 *parent = (*scopeInfo)->parent;
while (parent && parent->bodyEnd != tok)
parent = parent->parent;
if (parent)
if (parent) {
*scopeInfo = parent;
if (debug)
throw std::runtime_error("Internal error: unmatched }");
if (debug)
throw std::runtime_error("Internal error: unmatched }");
}
}
return;
}

View File

@ -92,6 +92,7 @@ private:
TEST_CASE(simplifyUsing10335);
TEST_CASE(scopeInfo1);
TEST_CASE(scopeInfo2);
}
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);
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)