Skip to content
Merged
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
2 changes: 1 addition & 1 deletion lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10356,7 +10356,7 @@ bool Tokenizer::operatorEnd(const Token * tok)
return true;

tok = tok->next();
while (tok && !Token::Match(tok, "[=;{),]")) {
while (tok && !Token::Match(tok, "[=;{}),]")) {
if (Token::Match(tok, "const|volatile|override")) {
tok = tok->next();
} else if (tok->str() == "noexcept") {
Expand Down
61 changes: 38 additions & 23 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ class TestTokenizer : public TestFixture {
TEST_CASE(simplifyOperatorName27);
TEST_CASE(simplifyOperatorName28);
TEST_CASE(simplifyOperatorName29); // spaceship operator
TEST_CASE(simplifyOperatorName30);
TEST_CASE(simplifyOperatorName31); // #6342
TEST_CASE(simplifyOperatorName32); // #10256
TEST_CASE(simplifyOperatorName33); // #10138
Expand Down Expand Up @@ -5328,29 +5329,6 @@ class TestTokenizer : public TestFixture {
ASSERT_EQUALS(code, tokenizeAndStringify(code));
}

void simplifyOperatorName31() { // #6342
const char code[] = "template <typename T>\n"
"struct B {\n"
" typedef T A[3];\n"
" operator A& () { return x_; }\n"
" A x_;\n"
"};";
ASSERT_EQUALS("template < typename T >\nstruct B {\n\nT ( & operatorT ( ) ) [ 3 ] { return x_ ; }\nT x_ [ 3 ] ;\n} ;", tokenizeAndStringify(code));
ASSERT_EQUALS("", errout_str());
}

void simplifyOperatorName32() { // #10256
const char code[] = "void f(int* = nullptr) {}\n";
ASSERT_EQUALS("void f ( int * = nullptr ) { }", tokenizeAndStringify(code));
ASSERT_EQUALS("", errout_str());
}

void simplifyOperatorName33() { // #10138
const char code[] = "int (operator\"\" _ii)(unsigned long long v) { return v; }\n";
ASSERT_EQUALS("int operator\"\"_ii ( unsigned long long v ) { return v ; }", tokenizeAndStringify(code));
ASSERT_EQUALS("", errout_str());
}

void simplifyOperatorName10() { // #8746
const char code1[] = "using a::operator=;";
ASSERT_EQUALS("using a :: operator= ;", tokenizeAndStringify(code1));
Expand Down Expand Up @@ -5627,6 +5605,43 @@ class TestTokenizer : public TestFixture {
ASSERT_EQUALS("auto operator<=> ( ) ;", tokenizeAndStringify("auto operator<=>();", settings));
}

void simplifyOperatorName30() { // #14151
const char code[] = "struct S { int operator()() const { return 42; } };\n"
"int f() {\n"
" S s;\n"
" return int{ s.operator()() };\n"
"}\n";
ASSERT_EQUALS("struct S { int operator() ( ) const { return 42 ; } } ;\n"
"int f ( ) {\n"
"S s ;\n"
"return int { s . operator() ( ) } ;\n"
"}", tokenizeAndStringify(code));
ASSERT_EQUALS("", errout_str());
}

void simplifyOperatorName31() { // #6342
const char code[] = "template <typename T>\n"
"struct B {\n"
" typedef T A[3];\n"
" operator A& () { return x_; }\n"
" A x_;\n"
"};";
ASSERT_EQUALS("template < typename T >\nstruct B {\n\nT ( & operatorT ( ) ) [ 3 ] { return x_ ; }\nT x_ [ 3 ] ;\n} ;", tokenizeAndStringify(code));
ASSERT_EQUALS("", errout_str());
}

void simplifyOperatorName32() { // #10256
const char code[] = "void f(int* = nullptr) {}\n";
ASSERT_EQUALS("void f ( int * = nullptr ) { }", tokenizeAndStringify(code));
ASSERT_EQUALS("", errout_str());
}

void simplifyOperatorName33() { // #10138
const char code[] = "int (operator\"\" _ii)(unsigned long long v) { return v; }\n";
ASSERT_EQUALS("int operator\"\"_ii ( unsigned long long v ) { return v ; }", tokenizeAndStringify(code));
ASSERT_EQUALS("", errout_str());
}

void simplifyOverloadedOperators1() {
const char code[] = "struct S { void operator()(int); };\n"
"\n"
Expand Down