Improve ast generation for templated function parameters (#2803)

This commit is contained in:
shaneasd 2020-09-15 00:44:50 +08:00 committed by GitHub
parent a42976d656
commit 53a0760fdf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 2 deletions

View File

@ -1229,6 +1229,9 @@ void CheckUnusedVar::checkFunctionVariableUsage()
const Token *expr = varDecl ? varDecl : tok->astOperand1();
if (isInitialization)
expr = tok->previous();
// Is variable in lhs a union member?
if (tok->previous() && tok->previous()->variable() && tok->previous()->variable()->nameToken()->scope()->type == Scope::eUnion)
continue;

View File

@ -796,8 +796,19 @@ static void compileTerm(Token *&tok, AST_state& state)
}
} else if (!state.cpp || !Token::Match(tok, "new|delete %name%|*|&|::|(|[")) {
tok = skipDecl(tok);
while (tok->next() && tok->next()->isName())
tok = tok->next();
bool repeat = true;
while (repeat)
{
repeat = false;
if (Token::Match(tok->next(), "%name%")) {
tok = tok->next();
repeat = true;
}
if (Token::simpleMatch(tok->next(), "<") && Token::Match(tok->linkAt(1), "> %name%")) {
tok = tok->next()->link()->next();
repeat = true;
}
}
state.op.push(tok);
if (Token::Match(tok, "%name% <") && tok->linkAt(1))
tok = tok->linkAt(1);

View File

@ -494,6 +494,8 @@ private:
TEST_CASE(noCrash1);
TEST_CASE(noCrash2);
TEST_CASE(noCrash3);
// --check-config
TEST_CASE(checkConfiguration);
@ -8519,6 +8521,10 @@ private:
"template <> d<c>::d(const d &) {}\n"));
}
void noCrash3() {
ASSERT_NO_THROW(tokenizeAndStringify("void a(X<int> x, typename Y1::Y2<int, A::B::C, 2> y, Z z = []{});"));
}
void checkConfig(const char code[]) {
errout.str("");