Skip to content

Commit f8244fd

Browse files
Fix #14424 FP constStatement when using declaration matches variable name (#8150)
1 parent 6369e51 commit f8244fd

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lib/tokenize.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2697,6 +2697,9 @@ namespace {
26972697
return false;
26982698
}
26992699

2700+
if (tok1->tokAt(-1)->tokType() == Token::eType || tok1->tokAt(-1)->tokType() == Token::eName)
2701+
return false;
2702+
27002703
if (Token::Match(tok1->tokAt(-1), "class|struct|union|enum|namespace")) {
27012704
// fixme
27022705
return false;

test/testsimplifyusing.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class TestSimplifyUsing : public TestFixture {
7474
TEST_CASE(simplifyUsing35);
7575
TEST_CASE(simplifyUsing36);
7676
TEST_CASE(simplifyUsing37);
77+
TEST_CASE(simplifyUsing38);
7778

7879
TEST_CASE(simplifyUsing8970);
7980
TEST_CASE(simplifyUsing8971);
@@ -914,6 +915,16 @@ class TestSimplifyUsing : public TestFixture {
914915
ASSERT_EQUALS("", errout_str());
915916
}
916917

918+
void simplifyUsing38() {
919+
const char code[] = "using std::begin;\n" // #14424
920+
"using std::end;\n"
921+
"Unknown begin;\n"
922+
"int end;\n";
923+
const char expected[] = "Unknown begin ; int end ;";
924+
ASSERT_EQUALS(expected, tok(code));
925+
ASSERT_EQUALS("", errout_str());
926+
}
927+
917928
void simplifyUsing8970() {
918929
const char code[] = "using V = std::vector<int>;\n"
919930
"struct A {\n"

0 commit comments

Comments
 (0)