Skip to content

Commit 46e2331

Browse files
committed
CWG 3131
1 parent d1fba2b commit 46e2331

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

clang/include/clang/Sema/Sema.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11099,14 +11099,14 @@ class Sema final : public SemaBase {
1109911099
Scope *S, VarDecl *RangeVar, SourceLocation ColonLoc,
1110011100
SourceLocation CoawaitLoc,
1110111101
ArrayRef<MaterializeTemporaryExpr *> LifetimeExtendTemps,
11102-
BuildForRangeKind Kind, bool ForExpansionStmt,
11102+
BuildForRangeKind Kind, bool Constexpr,
1110311103
StmtResult *RebuildResult = nullptr,
1110411104
llvm::function_ref<StmtResult()> RebuildWithDereference = {});
1110511105

1110611106
/// Build the range variable of a range-based for loop or iterating
1110711107
/// expansion statement and return its DeclStmt.
11108-
StmtResult BuildCXXForRangeRangeVar(Scope *S, Expr *Range,
11109-
bool ForExpansionStmt);
11108+
StmtResult BuildCXXForRangeRangeVar(Scope *S, Expr *Range, QualType Type,
11109+
bool Constexpr = false);
1111011110

1111111111
/// FinishCXXForRangeStmt - Attach the body to a C++0x for-range statement.
1111211112
/// This is a separate step from ActOnCXXForRangeStmt because analysis of the

clang/lib/Sema/SemaStmt.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2427,14 +2427,14 @@ static bool ObjCEnumerationCollection(Expr *Collection) {
24272427
&& Collection->getType()->getAs<ObjCObjectPointerType>() != nullptr;
24282428
}
24292429

2430-
StmtResult Sema::BuildCXXForRangeRangeVar(Scope *S, Expr *Range,
2431-
bool ForExpansionStmt) {
2430+
StmtResult Sema::BuildCXXForRangeRangeVar(Scope *S, Expr *Range, QualType Type,
2431+
bool Constexpr) {
2432+
24322433
// Divide by 2, since the variables are in the inner scope (loop body).
24332434
const auto DepthStr = std::to_string(S->getDepth() / 2);
24342435
SourceLocation RangeLoc = Range->getBeginLoc();
2435-
VarDecl *RangeVar =
2436-
BuildForRangeVarDecl(*this, RangeLoc, Context.getAutoRRefDeductType(),
2437-
std::string("__range") + DepthStr, ForExpansionStmt);
2436+
VarDecl *RangeVar = BuildForRangeVarDecl(
2437+
*this, RangeLoc, Type, std::string("__range") + DepthStr, Constexpr);
24382438
if (FinishForRangeVarDecl(*this, RangeVar, Range, RangeLoc,
24392439
diag::err_for_range_deduction_failure))
24402440

@@ -2491,7 +2491,7 @@ StmtResult Sema::ActOnCXXForRangeStmt(
24912491

24922492
// Build auto && __range = range-init
24932493
auto RangeDecl =
2494-
BuildCXXForRangeRangeVar(S, Range, /*ForExpansionStmt=*/false);
2494+
BuildCXXForRangeRangeVar(S, Range, Context.getAutoRRefDeductType());
24952495
if (RangeDecl.isInvalid()) {
24962496
ActOnInitializerError(LoopVar);
24972497
return StmtError();
@@ -2704,7 +2704,7 @@ Sema::ForRangeBeginEndInfo Sema::BuildCXXForRangeBeginEndVars(
27042704
Scope *S, VarDecl *RangeVar, SourceLocation ColonLoc,
27052705
SourceLocation CoawaitLoc,
27062706
ArrayRef<MaterializeTemporaryExpr *> LifetimeExtendTemps,
2707-
BuildForRangeKind Kind, bool ForExpansionStmt, StmtResult *RebuildResult,
2707+
BuildForRangeKind Kind, bool Constexpr, StmtResult *RebuildResult,
27082708
llvm::function_ref<StmtResult()> RebuildWithDereference) {
27092709
QualType RangeVarType = RangeVar->getType();
27102710
SourceLocation RangeLoc = RangeVar->getLocation();
@@ -2740,10 +2740,10 @@ Sema::ForRangeBeginEndInfo Sema::BuildCXXForRangeBeginEndVars(
27402740
const auto DepthStr = std::to_string(S->getDepth() / 2);
27412741
VarDecl *BeginVar =
27422742
BuildForRangeVarDecl(*this, ColonLoc, AutoType,
2743-
std::string("__begin") + DepthStr, ForExpansionStmt);
2743+
std::string("__begin") + DepthStr, Constexpr);
27442744
VarDecl *EndVar =
27452745
BuildForRangeVarDecl(*this, ColonLoc, AutoType,
2746-
std::string("__end") + DepthStr, ForExpansionStmt);
2746+
std::string("__end") + DepthStr, Constexpr);
27472747

27482748
// Build begin-expr and end-expr and attach to __begin and __end variables.
27492749
ExprResult BeginExpr, EndExpr;
@@ -2953,7 +2953,7 @@ StmtResult Sema::BuildCXXForRangeStmt(
29532953
auto BeginRangeRefTy = RangeVar->getType().getNonReferenceType();
29542954
auto [BeginVar, EndVar, BeginExpr, EndExpr] = BuildCXXForRangeBeginEndVars(
29552955
S, RangeVar, ColonLoc, CoawaitLoc, LifetimeExtendTemps, Kind,
2956-
/*ForExpansionStmt=*/false, &RebuildResult, RebuildWithDereference);
2956+
/*Constexpr=*/false, &RebuildResult, RebuildWithDereference);
29572957

29582958
if (!RebuildResult.isUnset())
29592959
return RebuildResult;

0 commit comments

Comments
 (0)