From 172e3c4ac62bcbaf9855120f572f09d24970ec4b Mon Sep 17 00:00:00 2001 From: chrchr Date: Fri, 15 Mar 2024 18:43:20 +0100 Subject: [PATCH] Fix #12521 internalAstError with using declaration --- lib/tokenize.cpp | 4 ++-- test/testsimplifyusing.cpp | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 0680fcd3f47..d15169f815b 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2849,8 +2849,8 @@ bool Tokenizer::simplifyUsing() continue; Token* end = tok->tokAt(3); while (end && !Token::Match(end, "[;,]")) { - if (end->str() == "<" && end->link()) // skip template args - end = end->link()->next(); + if (end->str() == "<") // skip template args + end = end->findClosingBracket(); else end = end->next(); } diff --git a/test/testsimplifyusing.cpp b/test/testsimplifyusing.cpp index 2ae94df58af..46e0838b3e8 100644 --- a/test/testsimplifyusing.cpp +++ b/test/testsimplifyusing.cpp @@ -737,6 +737,16 @@ class TestSimplifyUsing : public TestFixture { ASSERT_EQUALS(expected, tok(code, Platform::Type::Native, /*debugwarnings*/ true)); ASSERT_EQUALS("", errout_str()); } + { + const char code[] = "class T : private std::vector> {\n" // #12521 + " using std::vector>::empty;\n" + "};\n"; + const char expected[] = "class T : private std :: vector < std :: pair < std :: string , const int * > > { " + "using empty = std :: vector < std :: pair < std :: string , const int * > > :: empty ; " + "} ;"; + ASSERT_EQUALS(expected, tok(code, Platform::Type::Native, /*debugwarnings*/ true)); + ASSERT_EQUALS("", errout_str()); + } } void simplifyUsing8970() {