Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions clang/lib/Sema/SemaExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8966,6 +8966,9 @@ ExprResult Sema::ActOnConditionalOp(SourceLocation QuestionLoc,
commonExpr = MatExpr.get();
}

if (commonExpr->getDependence() & ExprDependence::UnexpandedPack)
return ExprError();

opaqueValue = new (Context) OpaqueValueExpr(commonExpr->getExprLoc(),
commonExpr->getType(),
commonExpr->getValueKind(),
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/SemaTemplateVariadic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1510,7 +1510,7 @@ static void CheckFoldOperand(Sema &S, Expr *E) {
E = E->IgnoreImpCasts();
auto *OCE = dyn_cast<CXXOperatorCallExpr>(E);
if ((OCE && OCE->isInfixBinaryOp()) || isa<BinaryOperator>(E) ||
isa<AbstractConditionalOperator>(E)) {
isa<AbstractConditionalOperator>(E) || isa<RecoveryExpr>(E)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can't really do this I think? RecoveryExpr isn't always generated/always valid.

It seems to me that we shouldn't have created the RecoveryExpr here (or done the return ExprError) unless we had diagnosed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IIUC the frontend produces a RecoveryExpr on semantic errors that prevent forming well formed statements. In that case should it be always generated in case of semantic errors? Can you point an example where it is not always generated.

Copy link
Member

Choose a reason for hiding this comment

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

IIUC the frontend produces a RecoveryExpr on semantic errors that prevent forming well formed statements. In that case should it be always generated in case of semantic errors? Can you point an example where it is not always generated.

RecoveryExprs are only created if they’re enabled by some flag (-frecovery-ast iirc), otherwise, you just get ExprError():

ExprResult Sema::CreateRecoveryExpr(SourceLocation Begin, SourceLocation End,
ArrayRef<Expr *> SubExprs, QualType T) {
if (!Context.getLangOpts().RecoveryAST)
return ExprError();

S.Diag(E->getExprLoc(), diag::err_fold_expression_bad_operand)
<< E->getSourceRange()
<< FixItHint::CreateInsertion(E->getBeginLoc(), "(")
Expand Down
5 changes: 5 additions & 0 deletions clang/test/SemaCXX/fold_expr_typo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ template <typename... U> struct A {
foo<T>((... + static_cast<U>(1))); // expected-error {{expression contains unexpanded parameter pack 'T'}}
}
};

template <typename ... T>
void foo(T... Params) {
(Params ?: 1, ...); // expected-error {{expression not permitted as operand of fold expression}}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This feels like it is in desperate need of notes or better source locations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry for the late response, I've been busy with college and such. Do you mean the test itself? Or the diagnostic? g++ diagnostic shows the caret on the conditional operator, should we do something similar here?

}