Skip to content

Fix #15086 syntaxError for ternary with two inequalities - #8913

Open
chrchr-github wants to merge 5 commits into
cppcheck-opensource:mainfrom
chrchr-github:chr_15XXX
Open

chrchr-github wants to merge 5 commits into
cppcheck-opensource:mainfrom
chrchr-github:chr_15XXX

Conversation

@chrchr-github

Copy link
Copy Markdown
Collaborator

No description provided.

@danmar danmar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an AI review take it with a grain of salt. Please feel free to reject it by clicking on Resolve button

Verdict: the logic looks correct to me. An unmatched : cannot appear in valid template arguments, so returning 0 there only makes template detection stricter and should not introduce false positives. Real ternary template arguments still work (existing tests cover std::array<int, B ? 1 : 2> and nested ternaries), parenthesized ternaries are skipped via the link, and :: is a separate token so it is not affected. I built the branch locally and TestSimplifyTemplate, TestTokenizer, TestSimplifyTypedef, TestVarID and TestGarbage pass (1321 tests, 0 failed). The inline comments are only style/naming nits.

The PR title still says #15XXX; please replace it with the actual trac ticket number.

Comment thread lib/templatesimplifier.cpp Outdated
Comment thread lib/templatesimplifier.cpp
@chrchr-github

This comment was marked as resolved.

@danmar

This comment was marked as resolved.

@danmar

This comment was marked as resolved.

@chrchr-github chrchr-github changed the title Fix #15XXX syntaxError for ternary with two inequalities Fix #15086 syntaxError for ternary with two inequalities Oct 4, 2026
if (tok->str() != "<")
return 0;
if (Token::Match(tok->previous(), "%var% <"))
if (Token::Match(tok->previous(), "%var%|) <"))

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to handle

template <typename T, typename U>
bool f(U u, bool b) {
  return u.template operator()<T>() || b;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants