Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
May 23, 2024

Conversation

pfultz2
Copy link
Contributor

@pfultz2 pfultz2 commented May 11, 2024

No description provided.

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
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
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
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
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
Contributor Author

pfultz2 commented May 20, 2024

@chrchr-github @danmar Any more feedback?

lib/tokenize.cpp Outdated Show resolved Hide resolved
Copy link
Owner

@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 danmar:main May 23, 2024
63 checks passed
@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
3 participants