Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -10355,14 +10362,13 @@ 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 (mSettings.library.hasAnyTypeCheck("std::" + tok->str()) ||
mSettings.library.podtype("std::" + tok->str()) ||
isStdContainerOrIterator(tok, mSettings))
else if (isLibraryType(tok, mSettings))
insert = true;
else if (Token::simpleMatch(tok, "aligned_storage"))
insert = true;
Expand Down
18 changes: 12 additions & 6 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

{
Expand All @@ -5315,6 +5310,17 @@ 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 = "void move ( ) { }\n"
"void string ( ) { }\n"
"std :: string_view f ( ) { return std :: string ( ) ; }";
ASSERT_EQUALS(expected, tokenizeAndStringify(code));
}
}

void microsoftMemory() {
Expand Down
Loading