-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[Clang] Implement P0963R3 "Structured binding declaration as a condition" #130228
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
Changes from 5 commits
295b817
5cd91f8
ffe3922
2ae72b4
8dd6f82
da94831
c37a324
7ca3012
ecb03db
50e5ef6
1a3e41f
43a391c
0035c00
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 |
|---|---|---|
|
|
@@ -5218,16 +5218,28 @@ static bool EvaluateVarDecl(EvalInfo &Info, const VarDecl *VD) { | |
| return true; | ||
| } | ||
|
|
||
| static bool EvaluateDecompositionDeclInit(EvalInfo &Info, | ||
| const DecompositionDecl *DD); | ||
|
|
||
| static bool EvaluateDecl(EvalInfo &Info, const Decl *D) { | ||
| bool OK = true; | ||
|
|
||
| if (const VarDecl *VD = dyn_cast<VarDecl>(D)) | ||
| OK &= EvaluateVarDecl(Info, VD); | ||
|
|
||
| if (const DecompositionDecl *DD = dyn_cast<DecompositionDecl>(D)) | ||
| for (auto *BD : DD->flat_bindings()) | ||
| if (auto *VD = BD->getHoldingVar()) | ||
| OK &= EvaluateDecl(Info, VD); | ||
| if (const DecompositionDecl *DD = dyn_cast<DecompositionDecl>(D); | ||
| DD && !DD->isDecisionVariable()) | ||
| OK &= EvaluateDecompositionDeclInit(Info, DD); | ||
zyn0217 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return OK; | ||
| } | ||
|
|
||
| static bool EvaluateDecompositionDeclInit(EvalInfo &Info, | ||
| const DecompositionDecl *DD) { | ||
| bool OK = true; | ||
| for (auto *BD : DD->flat_bindings()) | ||
| if (auto *VD = BD->getHoldingVar()) | ||
| OK &= EvaluateDecl(Info, VD); | ||
|
||
|
|
||
| return OK; | ||
| } | ||
|
|
@@ -5251,6 +5263,10 @@ static bool EvaluateCond(EvalInfo &Info, const VarDecl *CondDecl, | |
| return false; | ||
| if (!EvaluateAsBooleanCondition(Cond, Result, Info)) | ||
| return false; | ||
| if (auto *DD = dyn_cast_if_present<DecompositionDecl>(CondDecl); | ||
| DD && DD->isDecisionVariable() && | ||
zyn0217 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| !EvaluateDecompositionDeclInit(Info, DD)) | ||
| return false; | ||
| return Scope.destroy(); | ||
| } | ||
|
|
||
|
|
@@ -5335,6 +5351,12 @@ static EvalStmtResult EvaluateSwitch(StmtResult &Result, EvalInfo &Info, | |
| if (!EvaluateInteger(SS->getCond(), Value, Info)) | ||
| return ESR_Failed; | ||
|
|
||
| if (auto *DD = | ||
| dyn_cast_if_present<DecompositionDecl>(SS->getConditionVariable()); | ||
| DD && DD->isDecisionVariable() && | ||
| !EvaluateDecompositionDeclInit(Info, DD)) | ||
| return ESR_Failed; | ||
|
|
||
| if (!CondScope.destroy()) | ||
| return ESR_Failed; | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.