Fix #10874 FP constStatement with extra parentheses in declaration (#3931)

This commit is contained in:
chrchr-github 2022-03-24 22:07:21 +01:00 committed by GitHub
parent 479af21405
commit 3630e9c49d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 2 deletions

View File

@ -814,7 +814,7 @@ static void compileTerm(Token *&tok, AST_state& state)
state.op.push(tok);
if (Token::Match(tok, "%name% <") && tok->linkAt(1))
tok = tok->linkAt(1);
else if (Token::Match(tok, "%name% ..."))
else if (Token::Match(tok, "%name% ...") || (state.op.size() == 1 && Token::Match(tok->previous(), "( %name% ) =")))
tok = tok->next();
tok = tok->next();
if (Token::Match(tok, "%str%")) {
@ -1467,7 +1467,7 @@ static Token * createAstAtToken(Token *tok, bool cpp)
while (tok2 && tok2 != endPar && tok2->str() != ";") {
if (tok2->str() == "<" && tok2->link()) {
tok2 = tok2->link();
} else if (Token::Match(tok2, "%name% %op%|(|[|.|:|::") || Token::Match(tok2->previous(), "[(;{}] %cop%|(")) {
} else if (Token::Match(tok2, "%name% )| %op%|(|[|.|:|::") || Token::Match(tok2->previous(), "[(;{}] %cop%|(")) {
init1 = tok2;
AST_state state1(cpp);
compileExpression(tok2, state1);

View File

@ -504,6 +504,14 @@ private:
"}\n");
ASSERT_EQUALS("", errout.str());
check("struct T {\n" // #10874
" T* p;\n"
"};\n"
"void f(T* t) {\n"
" for (decltype(t->p) (c) = t->p; ;) {}\n"
"}\n");
ASSERT_EQUALS("", errout.str());
check("void f(int i, std::vector<int*> v);\n" // #10880
"void g() {\n"
" f(1, { static_cast<int*>(nullptr) });\n"

View File

@ -6213,6 +6213,12 @@ private:
ASSERT_EQUALS("decltypex( var1=", testAst("decltype(x) var = 1;"));
ASSERT_EQUALS("a1bdecltypet((>2,(", testAst("a(1 > b(decltype(t)), 2);")); // #10271
ASSERT_EQUALS("decltypex({01:?", testAst("decltype(x){} ? 0 : 1;"));
ASSERT_EQUALS("Tp* Tt* forctp.=;;( tp.", testAst("struct T { T* p; };\n" // #10874
"void f(T * t) {\n"
" for (decltype(t->p) (c) = t->p; ;) {}\n"
"}\n"));
ASSERT_EQUALS("x0=a, stdtie::a(x=", testAst("int x = 0, a; std::tie(a) = x;\n"));
}
void astunaryop() { // unary operators