Skip to content

Commit 91bab06

Browse files
committed
[Clang] Handle ?: operator in fold expression
1 parent 55fb1ca commit 91bab06

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

clang/lib/Sema/SemaExpr.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8966,6 +8966,9 @@ ExprResult Sema::ActOnConditionalOp(SourceLocation QuestionLoc,
89668966
commonExpr = MatExpr.get();
89678967
}
89688968

8969+
if (commonExpr->getDependence() & ExprDependence::UnexpandedPack)
8970+
return ExprError();
8971+
89698972
opaqueValue = new (Context) OpaqueValueExpr(commonExpr->getExprLoc(),
89708973
commonExpr->getType(),
89718974
commonExpr->getValueKind(),

clang/lib/Sema/SemaTemplateVariadic.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1510,7 +1510,7 @@ static void CheckFoldOperand(Sema &S, Expr *E) {
15101510
E = E->IgnoreImpCasts();
15111511
auto *OCE = dyn_cast<CXXOperatorCallExpr>(E);
15121512
if ((OCE && OCE->isInfixBinaryOp()) || isa<BinaryOperator>(E) ||
1513-
isa<AbstractConditionalOperator>(E)) {
1513+
isa<AbstractConditionalOperator>(E) || isa<RecoveryExpr>(E)) {
15141514
S.Diag(E->getExprLoc(), diag::err_fold_expression_bad_operand)
15151515
<< E->getSourceRange()
15161516
<< FixItHint::CreateInsertion(E->getBeginLoc(), "(")

clang/test/SemaCXX/fold_expr_typo.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@ template <typename... U> struct A {
1212
foo<T>((... + static_cast<U>(1))); // expected-error {{expression contains unexpanded parameter pack 'T'}}
1313
}
1414
};
15+
16+
template <typename ... T>
17+
void foo(T... Params) {
18+
(Params ?: 1, ...); // expected-error {{expression not permitted as operand of fold expression}}
19+
}

0 commit comments

Comments
 (0)