]> granicus.if.org Git - clang/commitdiff
PR24440: Do not silently discard a fold-expression appearing as the operand of a...
authorRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 15 Feb 2017 19:57:10 +0000 (19:57 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 15 Feb 2017 19:57:10 +0000 (19:57 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@295224 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Parse/ParseExpr.cpp
lib/Sema/SemaTemplateVariadic.cpp
test/Parser/cxx1z-fold-expressions.cpp

index 0c09614547c3e8d89fbb5a36b54b910b28bdebbd..56c7685d9361c098b2f61902101f31207d6de5f7 100644 (file)
@@ -2409,7 +2409,7 @@ Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr,
       // fold-expressions, we'll need to allow multiple ArgExprs here.
       if (ArgExprs.size() == 1 && isFoldOperator(Tok.getKind()) &&
           NextToken().is(tok::ellipsis))
-        return ParseFoldExpression(Result, T);
+        return ParseFoldExpression(ArgExprs[0], T);
 
       ExprType = SimpleExpr;
       Result = Actions.ActOnParenListExpr(OpenLoc, Tok.getLocation(),
index 4ea04ac143a0512aeab2f86c9027f49b077f421c..9f572007d8a7760aa9085ffc91e16dfc5d222e24 100644 (file)
@@ -1015,6 +1015,11 @@ ExprResult Sema::ActOnCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
   CheckFoldOperand(*this, LHS);
   CheckFoldOperand(*this, RHS);
 
+  auto DiscardOperands = [&] {
+    CorrectDelayedTyposInExpr(LHS);
+    CorrectDelayedTyposInExpr(RHS);
+  };
+
   // [expr.prim.fold]p3:
   //   In a binary fold, op1 and op2 shall be the same fold-operator, and
   //   either e1 shall contain an unexpanded parameter pack or e2 shall contain
@@ -1022,6 +1027,7 @@ ExprResult Sema::ActOnCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
   if (LHS && RHS &&
       LHS->containsUnexpandedParameterPack() ==
           RHS->containsUnexpandedParameterPack()) {
+    DiscardOperands();
     return Diag(EllipsisLoc,
                 LHS->containsUnexpandedParameterPack()
                     ? diag::err_fold_expression_packs_both_sides
@@ -1035,6 +1041,7 @@ ExprResult Sema::ActOnCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
   if (!LHS || !RHS) {
     Expr *Pack = LHS ? LHS : RHS;
     assert(Pack && "fold expression with neither LHS nor RHS");
+    DiscardOperands();
     if (!Pack->containsUnexpandedParameterPack())
       return Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
              << Pack->getSourceRange();
index 030638583239be2083ec0a2745403008d1695340..b1f7318e410d82b7f4b23f1590d85e26ffab45b8 100644 (file)
@@ -34,3 +34,12 @@ template<int ...N> int bad9() { return (3 + ... * N); } // expected-error {{oper
 template<int ...N> int bad10() { return (3 ? ... : N); } // expected-error +{{}} expected-note {{to match}}
 template<int ...N> int bad11() { return (N + ... 0); } // expected-error {{expected a foldable binary operator}} expected-error {{expected expression}}
 template<int ...N> int bad12() { return (... N); } // expected-error {{expected expression}}
+
+template<typename ...T> void as_operand_of_cast(int a, T ...t) {
+  return
+    (int)(a + ... + undeclared_junk) + // expected-error {{undeclared}} expected-error {{does not contain any unexpanded}}
+    (int)(t + ... + undeclared_junk) + // expected-error {{undeclared}}
+    (int)(... + undeclared_junk) + // expected-error {{undeclared}} expected-error {{does not contain any unexpanded}}
+    (int)(undeclared_junk + ...) + // expected-error {{undeclared}}
+    (int)(a + ...); // expected-error {{does not contain any unexpanded}}
+}