Improve ast generation for templated function parameters (#2803)
This commit is contained in:
parent
a42976d656
commit
53a0760fdf
|
@ -1229,6 +1229,9 @@ void CheckUnusedVar::checkFunctionVariableUsage()
|
||||||
|
|
||||||
const Token *expr = varDecl ? varDecl : tok->astOperand1();
|
const Token *expr = varDecl ? varDecl : tok->astOperand1();
|
||||||
|
|
||||||
|
if (isInitialization)
|
||||||
|
expr = tok->previous();
|
||||||
|
|
||||||
// Is variable in lhs a union member?
|
// Is variable in lhs a union member?
|
||||||
if (tok->previous() && tok->previous()->variable() && tok->previous()->variable()->nameToken()->scope()->type == Scope::eUnion)
|
if (tok->previous() && tok->previous()->variable() && tok->previous()->variable()->nameToken()->scope()->type == Scope::eUnion)
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -796,8 +796,19 @@ static void compileTerm(Token *&tok, AST_state& state)
|
||||||
}
|
}
|
||||||
} else if (!state.cpp || !Token::Match(tok, "new|delete %name%|*|&|::|(|[")) {
|
} else if (!state.cpp || !Token::Match(tok, "new|delete %name%|*|&|::|(|[")) {
|
||||||
tok = skipDecl(tok);
|
tok = skipDecl(tok);
|
||||||
while (tok->next() && tok->next()->isName())
|
bool repeat = true;
|
||||||
tok = tok->next();
|
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);
|
state.op.push(tok);
|
||||||
if (Token::Match(tok, "%name% <") && tok->linkAt(1))
|
if (Token::Match(tok, "%name% <") && tok->linkAt(1))
|
||||||
tok = tok->linkAt(1);
|
tok = tok->linkAt(1);
|
||||||
|
|
|
@ -494,6 +494,8 @@ private:
|
||||||
TEST_CASE(noCrash1);
|
TEST_CASE(noCrash1);
|
||||||
TEST_CASE(noCrash2);
|
TEST_CASE(noCrash2);
|
||||||
|
|
||||||
|
TEST_CASE(noCrash3);
|
||||||
|
|
||||||
// --check-config
|
// --check-config
|
||||||
TEST_CASE(checkConfiguration);
|
TEST_CASE(checkConfiguration);
|
||||||
|
|
||||||
|
@ -8519,6 +8521,10 @@ private:
|
||||||
"template <> d<c>::d(const d &) {}\n"));
|
"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[]) {
|
void checkConfig(const char code[]) {
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue