diff options
| author | Richard Smith <richard-llvm@metafoo.co.uk> | 2016-06-23 08:41:20 +0000 |
|---|---|---|
| committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2016-06-23 08:41:20 +0000 |
| commit | 19f877c3f2625188b73e77635a409a8ab925ca11 (patch) | |
| tree | 1cf9c635e6a7465c6c1c6489caac41ffd17c467b /clang/lib/Sema/SemaExprCXX.cpp | |
| parent | 26036843724d49fcd4678f177c02f0097997c731 (diff) | |
| download | bcm5719-llvm-19f877c3f2625188b73e77635a409a8ab925ca11.tar.gz bcm5719-llvm-19f877c3f2625188b73e77635a409a8ab925ca11.zip | |
Rearrange condition handling so that semantic checks on a condition variable
are performed before the other substatements of the construct are parsed,
rather than deferring them until the end. This allows better error recovery
from semantic errors in the condition, improves diagnostic order, and is a
prerequisite for C++17 constexpr if.
llvm-svn: 273548
Diffstat (limited to 'clang/lib/Sema/SemaExprCXX.cpp')
| -rw-r--r-- | clang/lib/Sema/SemaExprCXX.cpp | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index d5e944fa110..f97b9c9d81b 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -3054,11 +3054,21 @@ void Sema::CheckVirtualDtorCall(CXXDestructorDecl *dtor, SourceLocation Loc, } } +Sema::ConditionResult Sema::ActOnConditionVariable(Decl *ConditionVar, + SourceLocation StmtLoc, + ConditionKind CK) { + ExprResult E = + CheckConditionVariable(cast<VarDecl>(ConditionVar), StmtLoc, CK); + if (E.isInvalid()) + return ConditionError(); + return ConditionResult(ConditionVar, MakeFullExpr(E.get(), StmtLoc)); +} + /// \brief Check the use of the given variable as a C++ condition in an if, /// while, do-while, or switch statement. ExprResult Sema::CheckConditionVariable(VarDecl *ConditionVar, SourceLocation StmtLoc, - bool ConvertToBoolean) { + ConditionKind CK) { if (ConditionVar->isInvalidDecl()) return ExprError(); @@ -3082,13 +3092,15 @@ ExprResult Sema::CheckConditionVariable(VarDecl *ConditionVar, MarkDeclRefReferenced(cast<DeclRefExpr>(Condition.get())); - if (ConvertToBoolean) { - Condition = CheckBooleanCondition(Condition.get(), StmtLoc); - if (Condition.isInvalid()) - return ExprError(); + switch (CK) { + case ConditionKind::Boolean: + return CheckBooleanCondition(StmtLoc, Condition.get()); + + case ConditionKind::Switch: + return CheckSwitchCondition(StmtLoc, Condition.get()); } - return Condition; + llvm_unreachable("unexpected condition kind"); } /// CheckCXXBooleanCondition - Returns true if a conversion to bool is invalid. |

