Skip to content

Commit 7d6b68a

Browse files
committed
add tests and remove bogus assert
1 parent c138801 commit 7d6b68a

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

clang/lib/Sema/SemaExpr.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20628,10 +20628,8 @@ Sema::ConditionResult Sema::ActOnCondition(Scope *S, SourceLocation Loc,
2062820628
break;
2062920629

2063020630
case ConditionKind::ConstexprIf:
20631+
// Note: this might produce a FullExpr
2063120632
Cond = CheckBooleanCondition(Loc, SubExpr, true);
20632-
assert(isa<FullExpr>(Cond.get()) &&
20633-
"we should have converted this expression to a FullExpr before "
20634-
"evaluating it");
2063520633
break;
2063620634

2063720635
case ConditionKind::Switch:
@@ -20643,10 +20641,12 @@ Sema::ConditionResult Sema::ActOnCondition(Scope *S, SourceLocation Loc,
2064320641
{SubExpr}, PreferredConditionType(CK));
2064420642
if (!Cond.get())
2064520643
return ConditionError();
20646-
}
20647-
if (!isa<FullExpr>(Cond.get()))
20644+
} else if (Cond.isUsable() && !isa<FullExpr>(Cond.get()))
2064820645
Cond = ActOnFinishFullExpr(Cond.get(), Loc, /*DiscardedValue*/ false);
2064920646

20647+
if (Cond.isInvalid())
20648+
return ConditionError();
20649+
2065020650
return ConditionResult(*this, nullptr, Cond,
2065120651
CK == ConditionKind::ConstexprIf);
2065220652
}

clang/test/SemaCXX/cxx2a-constexpr-dynalloc.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,13 @@ struct S {
252252
};
253253

254254
int f() {
255-
if constexpr((S{}, true)) {
255+
if constexpr((S{}, true)) { // expected-warning{{left operand of comma operator has no effect}}
256+
return 1;
257+
}
258+
if constexpr(S s; (s, true)) { // expected-warning{{left operand of comma operator has no effect}}
259+
return 1;
260+
}
261+
if constexpr(S s; (s, true)) { // expected-warning{{left operand of comma operator has no effect}}
256262
return 1;
257263
}
258264
return 0;

0 commit comments

Comments
 (0)