Fixed #9110 (Syntax error on valid C++ code) (#1813)

This commit is contained in:
IOBYTE 2019-04-29 09:17:37 -04:00 committed by Daniel Marjamäki
parent ae8a3aae8d
commit 505b7f7ebd
2 changed files with 14 additions and 1 deletions

View File

@ -9164,7 +9164,7 @@ void Tokenizer::findGarbageCode() const
syntaxError(tok);
if (Token::Match(tok, "%cop%|= ]") && !(isCPP() && Token::Match(tok->previous(), "[|, &|= ]")))
syntaxError(tok);
if (Token::Match(tok, "[+-] [;,)]}]"))
if (Token::Match(tok, "[+-] [;,)]}]") && !(isCPP() && Token::Match(tok->previous(), "operator [+-] ;")))
syntaxError(tok);
}

View File

@ -397,6 +397,7 @@ private:
TEST_CASE(simplifyOperatorName9); // ticket #5709 - comma operator not properly tokenized
TEST_CASE(simplifyOperatorName10); // #8746 - using a::operator=
TEST_CASE(simplifyOperatorName11); // #8889
TEST_CASE(simplifyOperatorName12); // #9110
TEST_CASE(simplifyNullArray);
@ -6214,6 +6215,18 @@ private:
ASSERT_EQUALS("template < typename T > void g ( S < & T :: template operator- < double > > ) { }", tokenizeAndStringify(code4));
}
void simplifyOperatorName12() { // #9110
const char code[] = "namespace a {"
"template <typename b> void operator+(b);"
"}"
"using a::operator+;";
ASSERT_EQUALS("namespace a { "
"template < typename b > void operator+ ( b ) ; "
"} "
"using a :: operator+ ;",
tokenizeAndStringify(code));
}
void simplifyNullArray() {
ASSERT_EQUALS("* ( foo . bar [ 5 ] ) = x ;", tokenizeAndStringify("0[foo.bar[5]] = x;"));
}