r295224 - PR24440: Do not silently discard a fold-expression appearing as the operand of a cast-expression.

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 15 12:14:57 PST 2017


Hans, this would be a good candidate for Clang 4. The bug in question is
not a regression, but it is an accepts-invalid / wrong-code bug.

On 15 February 2017 at 11:57, Richard Smith via cfe-commits <
cfe-commits at lists.llvm.org> wrote:

> Author: rsmith
> Date: Wed Feb 15 13:57:10 2017
> New Revision: 295224
>
> URL: http://llvm.org/viewvc/llvm-project?rev=295224&view=rev
> Log:
> PR24440: Do not silently discard a fold-expression appearing as the
> operand of a cast-expression.
>
> Modified:
>     cfe/trunk/lib/Parse/ParseExpr.cpp
>     cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp
>     cfe/trunk/test/Parser/cxx1z-fold-expressions.cpp
>
> Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/
> ParseExpr.cpp?rev=295224&r1=295223&r2=295224&view=diff
> ============================================================
> ==================
> --- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
> +++ cfe/trunk/lib/Parse/ParseExpr.cpp Wed Feb 15 13:57:10 2017
> @@ -2409,7 +2409,7 @@ Parser::ParseParenExpression(ParenParseO
>        // 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(),
>
> Modified: cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/
> SemaTemplateVariadic.cpp?rev=295224&r1=295223&r2=295224&view=diff
> ============================================================
> ==================
> --- cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp Wed Feb 15 13:57:10 2017
> @@ -1015,6 +1015,11 @@ ExprResult Sema::ActOnCXXFoldExpr(Source
>    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(Source
>    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(Source
>    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();
>
> Modified: cfe/trunk/test/Parser/cxx1z-fold-expressions.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/
> cxx1z-fold-expressions.cpp?rev=295224&r1=295223&r2=295224&view=diff
> ============================================================
> ==================
> --- cfe/trunk/test/Parser/cxx1z-fold-expressions.cpp (original)
> +++ cfe/trunk/test/Parser/cxx1z-fold-expressions.cpp Wed Feb 15 13:57:10
> 2017
> @@ -34,3 +34,12 @@ template<int ...N> int bad9() { return (
>  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}}
> +}
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170215/c2c163e5/attachment-0001.html>


More information about the cfe-commits mailing list