From 18b60d2f2b66ae09e4cfa8986b9d146a5ff784dd Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Sat, 3 Jun 2023 15:13:15 +0200 Subject: [PATCH] Fix #11670 FP constStatement (inconclusive) triggered by namespace (#5114) --- lib/tokenize.cpp | 6 +++--- test/testsimplifyusing.cpp | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 17cb6451e..177407e7f 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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; } diff --git a/test/testsimplifyusing.cpp b/test/testsimplifyusing.cpp index 2b147aee2..1a6e2fde1 100644 --- a/test/testsimplifyusing.cpp +++ b/test/testsimplifyusing.cpp @@ -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 \n" + " struct S {\n" + " using iterator = T*;\n" + " iterator begin();\n" + " };\n" + "}\n" + "using I = N::S;\n" + "void f() {\n" + " I::iterator iter;\n" + "}\n"; + const char expected[] = "namespace N { struct S ; } " + "void f ( ) { int * iter ; } " + "struct N :: S { int * begin ( ) ; } ;"; + ASSERT_EQUALS(expected, tok(code)); + } + void simplifyUsing8970() { const char code[] = "using V = std::vector;\n" "struct A {\n"