Skip to content

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

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

chrchr-github wants to merge 2 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.

return 0;

unsigned int level = 0;
unsigned int inTernary = 0;

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

Minor naming nit: inTernary reads like a bool, but it is a nesting counter. Something like ternaryLevel would match the existing level variable in this function and make --ternaryLevel read more naturally.

// Skip '=', '?', ':'
if (Token::Match(tok, "=|?|:"))
if (Token::Match(tok, "=|?|:")) {
if (tok->str()[0] == '?')

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

Since the surrounding code compares whole strings (tok->str() == ">", tok->str() == ","), tok->str() == "?" / tok->str() == ":" would be more consistent and would not rely on the Token::Match above to rule out other tokens starting with those characters. It might also be worth updating the // Skip '=', '?', ':' comment to say that an unmatched : means this is not a template argument list.

@chrchr-github

Copy link
Copy Markdown
Collaborator Author

@danmar For some reason, I can't log in to my Trac account. Could you please check?

@danmar

danmar commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator

@chrchr-github sorry for slow reply. I moved trac to a new server. And trac has been updated. We now run python3 on the server instead of python2.

your hash had an old MD5 format that is not supported right now. So we have two options:

  • I can tweak the server to support your format also.
  • you can send me a new hash

your hash format was dropped because it was less safe, so I would recommend the second option. please feel free to email me a new hash.

there are only 2 others that have this specific problem also so it's ok to ask for new hashes..

@danmar

danmar commented Oct 4, 2026 •

Copy link
Copy Markdown
Collaborator

we support a range of hash formats but claude suggests a bcrypt hash:

htpasswd -nB chrchr

That's in apache2-utils on Debian/Ubuntu and httpd-tools on Fedora. If you don't have htpasswd, Python works too:

python3 -c "import bcrypt,getpass; print('chrchr:' + bcrypt.hashpw(getpass.getpass().encode(), bcrypt.gensalt()).decode())"

(that needs pip install bcrypt)

It looks like chrchr:$2y$05$… or chrchr:$2b$12$….

supported formats:

Format Prefix Recommended?
bcrypt $2y$, $2b$, $2a$ Yes. This is what htpasswd -B makes, and it's the server's default for new passwords
SHA-512 crypt $6$ Yes, this is fine too
SHA-256 crypt $5$ OK
Apache MD5 $apr1$ Weak. It's htpasswd's old default
MD5-crypt $1$ Weak. It only works with a standard salt (./0-9A-Za-z)
DES crypt 13 characters, no prefix No. Only the first 8 characters of the password count
SHA-1 {SHA} No, it has no salt

@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
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