Skip to content

Commit ca50dea

Browse files
committed
Fix in Tokenizer::simplifyUsing for non-scopes
1 parent 9619687 commit ca50dea

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

.travis_suppressions

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ bitwiseOnBoolean
99
unusedPrivateFunction:test/test*.cpp
1010
useStlAlgorithm
1111
simplifyUsing:lib/valueptr.h
12-
simplifyUsingUnmatchedBodyEnd
1312

1413
# debug suppressions
1514
valueFlowBailout

lib/tokenize.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1915,10 +1915,11 @@ namespace {
19151915
ScopeInfo3 *parent = (*scopeInfo)->parent;
19161916
while (parent && parent->bodyEnd != tok)
19171917
parent = parent->parent;
1918-
if (parent)
1918+
if (parent) {
19191919
*scopeInfo = parent;
1920-
if (debug)
1921-
throw std::runtime_error("Internal error: unmatched }");
1920+
if (debug)
1921+
throw std::runtime_error("Internal error: unmatched }");
1922+
}
19221923
}
19231924
return;
19241925
}

test/testsimplifyusing.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ class TestSimplifyUsing : public TestFixture {
9292
TEST_CASE(simplifyUsing10335);
9393

9494
TEST_CASE(scopeInfo1);
95+
TEST_CASE(scopeInfo2);
9596
}
9697

9798
std::string tok(const char code[], bool simplify = true, Settings::PlatformType type = Settings::Native, bool debugwarnings = true) {
@@ -1324,6 +1325,18 @@ class TestSimplifyUsing : public TestFixture {
13241325
tok(code, true);
13251326
ASSERT_EQUALS("", errout.str());
13261327
}
1328+
1329+
void scopeInfo2() {
1330+
const char code[] = "struct A {\n"
1331+
" using Map = std::map<int, int>;\n"
1332+
" Map values;\n"
1333+
"};\n"
1334+
"\n"
1335+
"static void getInitialProgramState(const A::Map& vars = A::Map {})\n"
1336+
"{}\n";
1337+
tok(code, true);
1338+
ASSERT_EQUALS("", errout.str());
1339+
}
13271340
};
13281341

13291342
REGISTER_TEST(TestSimplifyUsing)

0 commit comments

Comments
 (0)