Repository navigation
Fix #12551: false positive: missingReturn with switch-like constexpr if-chain in template #9098
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -407,8 +407,20 @@ static const Token *checkMissingReturnScope(const Token *tok, const Library &lib | |
| const Token *condition = paren->astOperand2(); | ||
| if (condition && condition->hasKnownIntValue() && condition->getKnownIntValue() == 1) | ||
| return checkMissingReturnScope(tok, library); | ||
| const Token *ifTok = paren->previous(); | ||
| while (Token::simpleMatch(ifTok->tokAt(-3), "} else {") && ifTok->previous()->isInsertedBrace()) | ||
| ifTok = ifTok->linkAt(-3)->linkAt(-1)->previous(); | ||
| if (isExhaustiveIfChain(ifTok)) | ||
| return checkMissingReturnScope(tok, library); | ||
| return tok; | ||
| } else if (tok->scope()->type == ScopeType::eElse) { | ||
| const Token *ifEnd = tok->link()->tokAt(-2); | ||
| if (Token::simpleMatch(ifEnd, "} else {")) { | ||
| // else branch is unreachable if condition is always true | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AI review This new handling of a known-true condition in front of an |
||
| const Token *condition = ifEnd->link()->linkAt(-1)->astOperand2(); | ||
| if (condition && condition->hasKnownIntValue() && condition->getKnownIntValue() != 0) | ||
| return checkMissingReturnScope(ifEnd, library); | ||
| } | ||
| const Token *errorToken = checkMissingReturnScope(tok, library); | ||
| if (errorToken) | ||
| return errorToken; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AI review
If
exprhas no value type, this check passes and the chain counts as exhaustive. Then a non-enum or unknown-typed expression matched against all enumerators suppressesmissingReturn. Base warned for both of these, the PR does not:The same happens for
s->xwhereSis incomplete. It may be better to accept a missing value type only for a non-type template parameter whose declared type is the enum, and reject it otherwise.