fix #9771 (Syntax error; operator != <> ()) (#2757)

This commit is contained in:
IOBYTE 2020-08-26 12:39:33 -04:00 committed by GitHub
parent bb5cad42cd
commit 8774e97f26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -9667,7 +9667,7 @@ void Tokenizer::findGarbageCode() const
}
if (Token::Match(tok, "[!|+-/%^~] )|]"))
syntaxError(tok);
if (Token::Match(tok, "==|!=|<=|>= %comp%"))
if (Token::Match(tok, "==|!=|<=|>= %comp%") && tok->strAt(-1) != "operator")
syntaxError(tok, tok->str() + " " + tok->strAt(1));
}

View File

@ -76,6 +76,7 @@ private:
TEST_CASE(tokenize36); // #8436
TEST_CASE(tokenize37); // #8550
TEST_CASE(tokenize38); // #9569
TEST_CASE(tokenize39); // #9771
TEST_CASE(validate);
@ -899,6 +900,16 @@ private:
ASSERT_EQUALS(exp, tokenizeAndStringify(code));
}
void tokenize39() { // #9771
const char code[] = "template <typename T> class Foo;"
"template <typename T> bool operator!=(const Foo<T> &, const Foo<T> &);"
"template <typename T> class Foo { friend bool operator!= <> (const Foo<T> &, const Foo<T> &); };";
const char exp[] = "template < typename T > class Foo ; "
"template < typename T > bool operator!= ( const Foo < T > & , const Foo < T > & ) ; "
"template < typename T > class Foo { friend bool operator!= < > ( const Foo < T > & , const Foo < T > & ) ; } ;";
ASSERT_EQUALS(exp, tokenizeAndStringify(code));
}
void validate() {
// C++ code in C file
ASSERT_THROW(tokenizeAndStringify(";using namespace std;",false,false,Settings::Native,"test.c"), InternalError);