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

Fixed exception dispatch idiom not being recognized in the middle of a function #6490

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

JohnSiegel
Copy link

@JohnSiegel JohnSiegel commented Jun 6, 2024

The existing check for the exception dispatch idiom only checks the beginning of a function. This PR checks the entire function for the idiom, and adds 3 new unit tests.

@JohnSiegel
Copy link
Author

Sorry about the failed build, I mistakenly built with an older version of the source. Should be good now.

for (const Token *tok = function->functionScope->bodyStart->next();
tok != function->functionScope->bodyEnd; tok = tok->next()) {
tok != function->functionScope->bodyEnd &&
!Token::simpleMatch(tok, "try { throw ; } catch ("); tok = tok->next()) {
Copy link
Owner

Choose a reason for hiding this comment

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

hmm you could also put this condition in the loop body.

 if (Token::simpleMatch(tok, "try { throw ; } catch ("))
     break;

I don't have a really strong opinion but feel that it's imho a bit preferable since the loop condition will be easier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants