Fix #9468 (Syntax error on valid C++) (#2358)

This commit is contained in:
IOBYTE 2019-11-14 03:26:21 -05:00 committed by Daniel Marjamäki
parent 1d19f57c5e
commit 2eb575d990
2 changed files with 17 additions and 1 deletions

View File

@ -10839,7 +10839,7 @@ void Tokenizer::simplifyOperatorName()
return;
for (Token *tok = list.front(); tok; tok = tok->next()) {
if (Token::Match(tok, "using|:: operator %op% ;")) {
if (Token::Match(tok, "using|:: operator %op%|%name% ;")) {
tok->next()->str("operator" + tok->strAt(2));
tok->next()->deleteNext();
continue;

View File

@ -399,6 +399,7 @@ private:
TEST_CASE(simplifyOperatorName12); // #9110
TEST_CASE(simplifyOperatorName13); // user defined literal
TEST_CASE(simplifyOperatorName14); // std::complex operator "" if
TEST_CASE(simplifyOperatorName15); // ticket #9468 syntaxError
TEST_CASE(simplifyNullArray);
@ -6378,6 +6379,21 @@ private:
}
}
void simplifyOperatorName15() { // ticket #9468 syntaxError
const char code[] = "template <typename> struct a;"
"template <typename> struct b {"
" typedef char c;"
" operator c();"
"};"
"template <> struct a<char> : b<char> { using b::operator char; };";
ASSERT_EQUALS("struct a<char> ; template < typename > struct a ; "
"struct b<char> ; "
"struct a<char> : b<char> { using b :: operatorchar ; } ; struct b<char> { "
"operatorchar ( ) ; "
"} ;",
tokenizeAndStringify(code));
}
void simplifyNullArray() {
ASSERT_EQUALS("* ( foo . bar [ 5 ] ) = x ;", tokenizeAndStringify("0[foo.bar[5]] = x;"));
}