Fixed #8746 (Syntax error, AST broken (using a::operator=))

This commit is contained in:
Daniel Marjamäki 2018-09-09 21:11:45 +02:00
parent 1bb1c4cc8e
commit 523a9c1c4a
2 changed files with 24 additions and 6 deletions

View File

@ -9765,7 +9765,22 @@ void Tokenizer::simplifyOperatorName()
if (isC()) if (isC())
return; return;
bool isUsingStmt = false;
for (Token *tok = list.front(); tok; tok = tok->next()) { for (Token *tok = list.front(); tok; tok = tok->next()) {
if (tok->str() == ";") {
if (isUsingStmt && Token::Match(tok->tokAt(-3), "using|:: operator %op% ;")) {
tok->previous()->previous()->str("operator" + tok->previous()->str());
tok->deletePrevious();
}
isUsingStmt = false;
continue;
}
if (tok->str() == "using") {
isUsingStmt = true;
continue;
}
if (tok->str() != "operator") if (tok->str() != "operator")
continue; continue;
// operator op // operator op
@ -9783,18 +9798,15 @@ void Tokenizer::simplifyOperatorName()
par = par->next(); par = par->next();
} }
done = false; done = false;
} } else if (Token::Match(par, ".|%op%|,")) {
if (Token::Match(par, ".|%op%|,")) {
op += par->str(); op += par->str();
par = par->next(); par = par->next();
done = false; done = false;
} } else if (Token::simpleMatch(par, "[ ]")) {
if (Token::simpleMatch(par, "[ ]")) {
op += "[]"; op += "[]";
par = par->tokAt(2); par = par->tokAt(2);
done = false; done = false;
} } else if (Token::Match(par, "( *| )")) {
if (Token::Match(par, "( *| )")) {
// break out and simplify.. // break out and simplify..
if (operatorEnd(par->next())) if (operatorEnd(par->next()))
break; break;

View File

@ -391,6 +391,7 @@ private:
TEST_CASE(simplifyOperatorName7); // ticket #4619 TEST_CASE(simplifyOperatorName7); // ticket #4619
TEST_CASE(simplifyOperatorName8); // ticket #5706 TEST_CASE(simplifyOperatorName8); // ticket #5706
TEST_CASE(simplifyOperatorName9); // ticket #5709 - comma operator not properly tokenized TEST_CASE(simplifyOperatorName9); // ticket #5709 - comma operator not properly tokenized
TEST_CASE(simplifyOperatorName10); // #8746 - using a::operator=
TEST_CASE(simplifyNullArray); TEST_CASE(simplifyNullArray);
@ -6123,6 +6124,11 @@ private:
ASSERT_EQUALS(code, tokenizeAndStringify(code)); ASSERT_EQUALS(code, tokenizeAndStringify(code));
} }
void simplifyOperatorName10() { // #8746
const char code[] = "using a::operator=;";
ASSERT_EQUALS("using a :: operator= ;", tokenizeAndStringify(code));
}
void simplifyNullArray() { void simplifyNullArray() {
ASSERT_EQUALS("* ( foo . bar [ 5 ] ) = x ;", tokenizeAndStringify("0[foo.bar[5]] = x;")); ASSERT_EQUALS("* ( foo . bar [ 5 ] ) = x ;", tokenizeAndStringify("0[foo.bar[5]] = x;"));
} }