Fix #11670 FP constStatement (inconclusive) triggered by namespace (#5114)

This commit is contained in:
chrchr-github 2023-06-03 15:13:15 +02:00 committed by GitHub
parent f2976e5bb5
commit 18b60d2f2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 3 deletions

View File

@ -3080,15 +3080,15 @@ bool Tokenizer::simplifyUsing()
tok1->deletePrevious();
break;
} else {
const std::string::size_type idx = fullScope.rfind(' ');
const std::string::size_type idx = fullScope.rfind("::");
if (idx == std::string::npos)
break;
if (tok1->strAt(-2) == fullScope.substr(idx + 1)) {
if (tok1->strAt(-2) == fullScope.substr(idx + 3)) {
tok1->deletePrevious();
tok1->deletePrevious();
fullScope.resize(idx - 3);
fullScope.resize(idx - 1);
} else
break;
}

View File

@ -71,6 +71,7 @@ private:
TEST_CASE(simplifyUsing24);
TEST_CASE(simplifyUsing25);
TEST_CASE(simplifyUsing26); // #11090
TEST_CASE(simplifyUsing27);
TEST_CASE(simplifyUsing8970);
TEST_CASE(simplifyUsing8971);
@ -656,6 +657,24 @@ private:
ASSERT_EQUALS(expected, tok(code));
}
void simplifyUsing27() { // #11670
const char code[] = "namespace N {\n"
" template <class T>\n"
" struct S {\n"
" using iterator = T*;\n"
" iterator begin();\n"
" };\n"
"}\n"
"using I = N::S<int>;\n"
"void f() {\n"
" I::iterator iter;\n"
"}\n";
const char expected[] = "namespace N { struct S<int> ; } "
"void f ( ) { int * iter ; } "
"struct N :: S<int> { int * begin ( ) ; } ;";
ASSERT_EQUALS(expected, tok(code));
}
void simplifyUsing8970() {
const char code[] = "using V = std::vector<int>;\n"
"struct A {\n"