Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions clang/lib/Sema/SemaExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20628,10 +20628,8 @@ Sema::ConditionResult Sema::ActOnCondition(Scope *S, SourceLocation Loc,
break;

case ConditionKind::ConstexprIf:
// Note: this might produce a FullExpr
Cond = CheckBooleanCondition(Loc, SubExpr, true);
assert(isa<FullExpr>(Cond.get()) &&
"we should have converted this expression to a FullExpr before "
"evaluating it");
break;

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

if (Cond.isInvalid())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (Cond.isInvalid())
if (!Cond.isUsable())

Unless there is a reason that ConditionResult would be ok with a 'null' expr?

return ConditionError();

return ConditionResult(*this, nullptr, Cond,
CK == ConditionKind::ConstexprIf);
}
Expand Down
8 changes: 7 additions & 1 deletion clang/test/SemaCXX/cxx2a-constexpr-dynalloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,13 @@ struct S {
};

int f() {
if constexpr((S{}, true)) {
if constexpr((S{}, true)) { // expected-warning{{left operand of comma operator has no effect}}
return 1;
}
if constexpr(S s; (s, true)) { // expected-warning{{left operand of comma operator has no effect}}
return 1;
}
if constexpr(S s; (s, true)) { // expected-warning{{left operand of comma operator has no effect}}
return 1;
}
return 0;
Expand Down
Loading