From 79a0d7d4fda0142af71635953d9efa7718e455ee Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 22 Apr 2026 10:05:03 +0200 Subject: [PATCH 1/4] Update tokenize.cpp --- lib/tokenize.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index ebccfc90687..e9699476846 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -10345,7 +10345,11 @@ void Tokenizer::simplifyNamespaceStd() continue; if (Token::Match(tok->previous(), ".|::|namespace")) continue; - if (Token::simpleMatch(tok->next(), "(")) { + if (mSettings.library.hasAnyTypeCheck("std::" + tok->str()) || + mSettings.library.podtype("std::" + tok->str()) || + isStdContainerOrIterator(tok, mSettings)) + insert = true; + else if (Token::simpleMatch(tok->next(), "(")) { if (TokenList::isFunctionHead(tok->next(), "{")) userFunctions.insert(tok->str()); else if (TokenList::isFunctionHead(tok->next(), ";")) { @@ -10360,10 +10364,6 @@ void Tokenizer::simplifyNamespaceStd() } else if (Token::simpleMatch(tok->next(), "<") && (isStdContainerOrIterator(tok, mSettings) || isStdSmartPointer(tok, mSettings))) insert = true; - else if (mSettings.library.hasAnyTypeCheck("std::" + tok->str()) || - mSettings.library.podtype("std::" + tok->str()) || - isStdContainerOrIterator(tok, mSettings)) - insert = true; else if (Token::simpleMatch(tok, "aligned_storage")) insert = true; From b1a82e2c9959f09d0ecb56a7d4ffccedfcb111d4 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 22 Apr 2026 10:06:04 +0200 Subject: [PATCH 2/4] Update testtokenize.cpp --- test/testtokenize.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 0798983c079..71cf747c688 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -5288,12 +5288,7 @@ class TestTokenizer : public TestFixture { "if ( ! p ) {\n" "throw std :: runtime_error ( \"abc\" ) ; }\n" "}"; - TODO_ASSERT_EQUALS(expected, - "void f ( const std :: unique_ptr < int > & p ) {\n" - "if ( ! p ) {\n" - "throw runtime_error ( \"abc\" ) ; }\n" - "}", - tokenizeAndStringify(code)); + ASSERT_EQUALS(expected, tokenizeAndStringify(code)); } { @@ -5315,6 +5310,12 @@ class TestTokenizer : public TestFixture { "}"; ASSERT_EQUALS(expected, tokenizeAndStringify(code)); } + { + const char code[] = "using namespace std;\n" + "string_view f() { return string(); }\n"; + expected = "std :: string_view f ( ) { return std :: string ( ) ; }"; + ASSERT_EQUALS(expected, tokenizeAndStringify(code)); + } } void microsoftMemory() { From 731d0fd19acb482e6b8dd98e737645e456805412 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 22 Apr 2026 12:32:37 +0200 Subject: [PATCH 3/4] Update tokenize.cpp [skip ci] --- lib/tokenize.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index e9699476846..01f94588e6d 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -10328,6 +10328,13 @@ static bool isStdSmartPointer(const Token* tok, const Settings& settings) return ptr && startsWith(ptr->name, "std::"); } +static bool isLibraryType(const Token* tok, const Settings& settings) +{ + return settings.library.hasAnyTypeCheck("std::" + tok->str()) || + settings.library.podtype("std::" + tok->str()) || + isStdContainerOrIterator(tok, settings); +} + // Add std:: in front of std classes, when using namespace std; was given void Tokenizer::simplifyNamespaceStd() { @@ -10345,11 +10352,7 @@ void Tokenizer::simplifyNamespaceStd() continue; if (Token::Match(tok->previous(), ".|::|namespace")) continue; - if (mSettings.library.hasAnyTypeCheck("std::" + tok->str()) || - mSettings.library.podtype("std::" + tok->str()) || - isStdContainerOrIterator(tok, mSettings)) - insert = true; - else if (Token::simpleMatch(tok->next(), "(")) { + if (Token::simpleMatch(tok->next(), "(")) { if (TokenList::isFunctionHead(tok->next(), "{")) userFunctions.insert(tok->str()); else if (TokenList::isFunctionHead(tok->next(), ";")) { @@ -10359,11 +10362,14 @@ void Tokenizer::simplifyNamespaceStd() if (start != tok && start->isName() && !start->isKeyword() && (!start->previous() || Token::Match(start->previous(), "[;{}]"))) userFunctions.insert(tok->str()); } - if (userFunctions.find(tok->str()) == userFunctions.end() && mSettings.library.matchArguments(tok, "std::" + tok->str())) + if ((userFunctions.find(tok->str()) == userFunctions.end() && mSettings.library.matchArguments(tok, "std::" + tok->str())) || + (tok->tokAt(-1)->isKeyword() && isLibraryType(tok, mSettings))) insert = true; } else if (Token::simpleMatch(tok->next(), "<") && (isStdContainerOrIterator(tok, mSettings) || isStdSmartPointer(tok, mSettings))) insert = true; + else if (isLibraryType(tok, mSettings)) + insert = true; else if (Token::simpleMatch(tok, "aligned_storage")) insert = true; From 541f9fd7b3c6078f08f6ac0d7438fc76a0215b23 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 22 Apr 2026 12:33:36 +0200 Subject: [PATCH 4/4] Update testtokenize.cpp --- test/testtokenize.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 71cf747c688..fd0a0d6aeb6 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -5310,10 +5310,15 @@ class TestTokenizer : public TestFixture { "}"; ASSERT_EQUALS(expected, tokenizeAndStringify(code)); } + { const char code[] = "using namespace std;\n" + "void move() {}\n" + "void string() {}\n" "string_view f() { return string(); }\n"; - expected = "std :: string_view f ( ) { return std :: string ( ) ; }"; + expected = "void move ( ) { }\n" + "void string ( ) { }\n" + "std :: string_view f ( ) { return std :: string ( ) ; }"; ASSERT_EQUALS(expected, tokenizeAndStringify(code)); } }