<div dir="ltr">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.</div><div class="gmail_extra"><br><div class="gmail_quote">On 15 February 2017 at 11:57, Richard Smith via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: rsmith<br>
Date: Wed Feb 15 13:57:10 2017<br>
New Revision: 295224<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=295224&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=295224&view=rev</a><br>
Log:<br>
PR24440: Do not silently discard a fold-expression appearing as the operand of a cast-expression.<br>
<br>
Modified:<br>
cfe/trunk/lib/Parse/ParseExpr.<wbr>cpp<br>
cfe/trunk/lib/Sema/<wbr>SemaTemplateVariadic.cpp<br>
cfe/trunk/test/Parser/cxx1z-<wbr>fold-expressions.cpp<br>
<br>
Modified: cfe/trunk/lib/Parse/ParseExpr.<wbr>cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=295224&r1=295223&r2=295224&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/Parse/<wbr>ParseExpr.cpp?rev=295224&r1=<wbr>295223&r2=295224&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/Parse/ParseExpr.<wbr>cpp (original)<br>
+++ cfe/trunk/lib/Parse/ParseExpr.<wbr>cpp Wed Feb 15 13:57:10 2017<br>
@@ -2409,7 +2409,7 @@ Parser::ParseParenExpression(<wbr>ParenParseO<br>
// fold-expressions, we'll need to allow multiple ArgExprs here.<br>
if (ArgExprs.size() == 1 && isFoldOperator(Tok.getKind()) &&<br>
NextToken().is(tok::ellipsis))<br>
- return ParseFoldExpression(Result, T);<br>
+ return ParseFoldExpression(ArgExprs[<wbr>0], T);<br>
<br>
ExprType = SimpleExpr;<br>
Result = Actions.ActOnParenListExpr(<wbr>OpenLoc, Tok.getLocation(),<br>
<br>
Modified: cfe/trunk/lib/Sema/<wbr>SemaTemplateVariadic.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp?rev=295224&r1=295223&r2=295224&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/Sema/<wbr>SemaTemplateVariadic.cpp?rev=<wbr>295224&r1=295223&r2=295224&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/Sema/<wbr>SemaTemplateVariadic.cpp (original)<br>
+++ cfe/trunk/lib/Sema/<wbr>SemaTemplateVariadic.cpp Wed Feb 15 13:57:10 2017<br>
@@ -1015,6 +1015,11 @@ ExprResult Sema::ActOnCXXFoldExpr(Source<br>
CheckFoldOperand(*this, LHS);<br>
CheckFoldOperand(*this, RHS);<br>
<br>
+ auto DiscardOperands = [&] {<br>
+ CorrectDelayedTyposInExpr(LHS)<wbr>;<br>
+ CorrectDelayedTyposInExpr(RHS)<wbr>;<br>
+ };<br>
+<br>
// [expr.prim.fold]p3:<br>
// In a binary fold, op1 and op2 shall be the same fold-operator, and<br>
// either e1 shall contain an unexpanded parameter pack or e2 shall contain<br>
@@ -1022,6 +1027,7 @@ ExprResult Sema::ActOnCXXFoldExpr(Source<br>
if (LHS && RHS &&<br>
LHS-><wbr>containsUnexpandedParameterPac<wbr>k() ==<br>
RHS-><wbr>containsUnexpandedParameterPac<wbr>k()) {<br>
+ DiscardOperands();<br>
return Diag(EllipsisLoc,<br>
LHS-><wbr>containsUnexpandedParameterPac<wbr>k()<br>
? diag::err_fold_expression_<wbr>packs_both_sides<br>
@@ -1035,6 +1041,7 @@ ExprResult Sema::ActOnCXXFoldExpr(Source<br>
if (!LHS || !RHS) {<br>
Expr *Pack = LHS ? LHS : RHS;<br>
assert(Pack && "fold expression with neither LHS nor RHS");<br>
+ DiscardOperands();<br>
if (!Pack-><wbr>containsUnexpandedParameterPac<wbr>k())<br>
return Diag(EllipsisLoc, diag::err_pack_expansion_<wbr>without_parameter_packs)<br>
<< Pack->getSourceRange();<br>
<br>
Modified: cfe/trunk/test/Parser/cxx1z-<wbr>fold-expressions.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx1z-fold-expressions.cpp?rev=295224&r1=295223&r2=295224&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/test/Parser/<wbr>cxx1z-fold-expressions.cpp?<wbr>rev=295224&r1=295223&r2=<wbr>295224&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/test/Parser/cxx1z-<wbr>fold-expressions.cpp (original)<br>
+++ cfe/trunk/test/Parser/cxx1z-<wbr>fold-expressions.cpp Wed Feb 15 13:57:10 2017<br>
@@ -34,3 +34,12 @@ template<int ...N> int bad9() { return (<br>
template<int ...N> int bad10() { return (3 ? ... : N); } // expected-error +{{}} expected-note {{to match}}<br>
template<int ...N> int bad11() { return (N + ... 0); } // expected-error {{expected a foldable binary operator}} expected-error {{expected expression}}<br>
template<int ...N> int bad12() { return (... N); } // expected-error {{expected expression}}<br>
+<br>
+template<typename ...T> void as_operand_of_cast(int a, T ...t) {<br>
+ return<br>
+ (int)(a + ... + undeclared_junk) + // expected-error {{undeclared}} expected-error {{does not contain any unexpanded}}<br>
+ (int)(t + ... + undeclared_junk) + // expected-error {{undeclared}}<br>
+ (int)(... + undeclared_junk) + // expected-error {{undeclared}} expected-error {{does not contain any unexpanded}}<br>
+ (int)(undeclared_junk + ...) + // expected-error {{undeclared}}<br>
+ (int)(a + ...); // expected-error {{does not contain any unexpanded}}<br>
+}<br>
<br>
<br>
______________________________<wbr>_________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div>