Fix issue 9524: Syntax Error: AST broken, 'if' doesn't have two operands. (#2432)
This commit is contained in:
parent
047418dda1
commit
56e17fb228
|
@ -601,11 +601,11 @@ static bool iscpp11init_impl(const Token * const tok)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isRefQualifier(const Token* tok)
|
static bool isQualifier(const Token* tok)
|
||||||
{
|
{
|
||||||
if (!Token::Match(tok, "&|&&"))
|
while (Token::Match(tok, "&|&&|*"))
|
||||||
return false;
|
tok = tok->next();
|
||||||
if (!Token::Match(tok->next(), "{|;"))
|
if (!Token::Match(tok, "{|;"))
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -977,7 +977,7 @@ static void compileMulDiv(Token *&tok, AST_state& state)
|
||||||
{
|
{
|
||||||
compilePointerToElem(tok, state);
|
compilePointerToElem(tok, state);
|
||||||
while (tok) {
|
while (tok) {
|
||||||
if (Token::Match(tok, "[/%]") || (tok->str() == "*" && !tok->astOperand1())) {
|
if (Token::Match(tok, "[/%]") || (tok->str() == "*" && !tok->astOperand1() && !isQualifier(tok))) {
|
||||||
if (Token::Match(tok, "* [*,)]")) {
|
if (Token::Match(tok, "* [*,)]")) {
|
||||||
Token* tok2 = tok->next();
|
Token* tok2 = tok->next();
|
||||||
while (tok2->next() && tok2->str() == "*")
|
while (tok2->next() && tok2->str() == "*")
|
||||||
|
@ -1036,7 +1036,7 @@ static void compileAnd(Token *&tok, AST_state& state)
|
||||||
{
|
{
|
||||||
compileEqComp(tok, state);
|
compileEqComp(tok, state);
|
||||||
while (tok) {
|
while (tok) {
|
||||||
if (tok->str() == "&" && !tok->astOperand1() && !isRefQualifier(tok)) {
|
if (tok->str() == "&" && !tok->astOperand1() && !isQualifier(tok)) {
|
||||||
Token* tok2 = tok->next();
|
Token* tok2 = tok->next();
|
||||||
if (!tok2)
|
if (!tok2)
|
||||||
break;
|
break;
|
||||||
|
@ -1075,7 +1075,7 @@ static void compileLogicAnd(Token *&tok, AST_state& state)
|
||||||
{
|
{
|
||||||
compileOr(tok, state);
|
compileOr(tok, state);
|
||||||
while (tok) {
|
while (tok) {
|
||||||
if (tok->str() == "&&" && !isRefQualifier(tok)) {
|
if (tok->str() == "&&" && !isQualifier(tok)) {
|
||||||
if (!tok->astOperand1()) {
|
if (!tok->astOperand1()) {
|
||||||
Token* tok2 = tok->next();
|
Token* tok2 = tok->next();
|
||||||
if (!tok2)
|
if (!tok2)
|
||||||
|
|
|
@ -8126,8 +8126,8 @@ private:
|
||||||
"}\n"))
|
"}\n"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// #9511
|
|
||||||
void checkRefQualifiers() {
|
void checkRefQualifiers() {
|
||||||
|
// #9511
|
||||||
ASSERT_NO_THROW(tokenizeAndStringify("class a {\n"
|
ASSERT_NO_THROW(tokenizeAndStringify("class a {\n"
|
||||||
" void b() && {\n"
|
" void b() && {\n"
|
||||||
" if (this) {}\n"
|
" if (this) {}\n"
|
||||||
|
@ -8166,6 +8166,15 @@ private:
|
||||||
" return x;\n"
|
" return x;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"};\n"))
|
"};\n"))
|
||||||
|
// #9524
|
||||||
|
ASSERT_NO_THROW(tokenizeAndStringify("auto f() -> int* {\n"
|
||||||
|
" if (0) {}\n"
|
||||||
|
" return 0;\n"
|
||||||
|
"};\n"))
|
||||||
|
ASSERT_NO_THROW(tokenizeAndStringify("auto f() -> int** {\n"
|
||||||
|
" if (0) {}\n"
|
||||||
|
" return 0;\n"
|
||||||
|
"};\n"))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue