Skip to content

Fix 12372: C++20: syntaxError with implicit operator and requires clause#6397

Merged
chrchr-github merged 3 commits intocppcheck-opensource:mainfrom
pfultz2:syntax-error-requires-operator
May 23, 2024
Merged

Fix 12372: C++20: syntaxError with implicit operator and requires clause#6397
chrchr-github merged 3 commits intocppcheck-opensource:mainfrom
pfultz2:syntax-error-requires-operator

Conversation

@pfultz2
Copy link
Copy Markdown
Contributor

@pfultz2 pfultz2 commented May 11, 2024

No description provided.

Comment thread lib/tokenize.cpp
for (tok = tok->next(); tok && !Token::Match(tok, ";|{"); tok = tok->next()) {
if (tok->link() && Token::Match(tok, "<|[|("))
tok = tok->link();
if (Token::simpleMatch(tok, "bool {"))
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.

Should this be "%bool% {"? But apparently it's not needed at all...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, this is for checking when doing explicit conversion to bool as the requires clause doesnt allow implicit conversion to bool so then the user will need to explicitly convert with either static_cast<bool>(...), (bool) ..., bool(...) or bool{...}. However, the latter(ie bool{}) will exit the loop on { so this extra check is there to continue with the explicit conversion.

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.

If it is needed for something, we should have a test for that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added test.

@pfultz2
Copy link
Copy Markdown
Contributor Author

pfultz2 commented May 20, 2024

@chrchr-github @danmar Any more feedback?

Comment thread lib/tokenize.cpp Outdated
Copy link
Copy Markdown
Collaborator

@danmar danmar left a comment

Choose a reason for hiding this comment

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

lgtm

@chrchr-github chrchr-github merged commit 06f5689 into cppcheck-opensource:main May 23, 2024
@pfultz2 pfultz2 deleted the syntax-error-requires-operator branch May 23, 2024 14:56
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.

3 participants