Skip to content

Fix #15314 internalError VarId set for bool literal - #9119

Open
wjakobsson wants to merge 2 commits into
cppcheck-opensource:mainfrom
wjakobsson:fix-15314
Open

wjakobsson wants to merge 2 commits into
cppcheck-opensource:mainfrom
wjakobsson:fix-15314

Conversation

@wjakobsson

Copy link
Copy Markdown
Collaborator

No description provided.

@dmcppcheck dmcppcheck left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

AI review

The PR fixes the static_assert / _Static_assert case, the requires case and the for (V v{…}, w{…};;) case of #15314. No regressions showed up in my tests. One variant still fails in the PR build: void k() noexcept(S::v && true); raises the same internalError: VarId set for bool literal. The reason is that S::v && true inside noexcept(...) of a function declaration is still parsed as a declaration of a reference named true. If the PR is meant to close #15314 completely, noexcept ( probably needs the same treatment as sizeof ( and static_assert (. This is not a regression: base gives the same error. I found no other problems.

Comments

# Comment By Where Status
1 noexcept(S::v && true) still gives internalError: VarId set for bool literal AI review lib/tokenize.cpp:4995 🆕 New

@wjakobsson, please fix, resolve or reply to the open and new comments: #1.

Testing

  • I built cppcheck and testrunner from pr/ and cppcheck from base/.
  • ./testrunner TestVarID TestTokenizer TestSimplifyTemplate TestSymbolDatabase ran 1321 tests and 0 failed.
  • I compared base and PR one line at a time, each line after struct S { static const bool v = false; };, with cppcheck --std=c++20 -q. A line counts as an error if the output contains internalError.
code base pr
static_assert(S::v && true, ""); (namespace scope) error ok
struct T { static_assert(S::v && true, ""); }; error ok
static_assert(S::v && true); error ok
requires clauses, decltype, explicit(...), template args, alignas, if ok ok
void k() noexcept(S::v && true); error error
struct A { void k() noexcept(S::v && true); }; error error
  • The for (V v{ 1, x, true }, w{ 2, x, false }; ;) case: base gives the inner x a new varid (x@var5) and the PR correctly keeps x@var1.
  • C files with _Static_assert(b && 1, "") and C23 static_assert give no errors.

The variant that still fails:

// n.cpp
struct S { static const bool v = false; };
void k() noexcept(S::v && true);
$ /work/pr/cppcheck -q n.cpp
n.cpp:2:27: error: Internal error. VarId set for bool literal. [internalError]
void k() noexcept(S::v && true);
                          ^

Automated review of 2d765dc by Claude. The pull request was built and tested locally.

Comment thread lib/tokenize.cpp
// No variable declarations in sizeof
if (Token::simpleMatch(tok->previous(), "sizeof (")) {
// No variable declarations in sizeof and static_assert
if (Token::Match(tok->previous(), "sizeof|_Static_assert (") ||

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

AI review

The same #15314 error still happens with noexcept:

struct S { static const bool v = false; };
void k() noexcept(S::v && true);

cppcheck -q n.cpp → n.cpp:2:27: error: Internal error. VarId set for bool literal. [internalError]. It also happens with a member declaration (struct A { void k() noexcept(S::v && true); };). Base has the same error, so this is not a regression, but it is the same bug through another keyword. Should noexcept ( be skipped here as well, like sizeof ( and static_assert (?

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