PR c++/68377 - parenthesized expr in fold-expression
authorJason Merrill <jason@redhat.com>
Thu, 17 Nov 2016 21:40:41 +0000 (16:40 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Thu, 17 Nov 2016 21:40:41 +0000 (16:40 -0500)
* parser.c (cp_parser_fold_expression): Check TREE_NO_WARNING.

From-SVN: r242561

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/g++.dg/cpp1z/fold8.C [new file with mode: 0644]

index 088a63cab8454f41b84f02f23a78cdcb46c9dc8d..5775ba64ac4ad6fceddc34f0a03e0c0c6633627d 100644 (file)
@@ -1,3 +1,8 @@
+2016-11-17  Jason Merrill  <jason@redhat.com>
+
+       PR c++/68377
+       * parser.c (cp_parser_fold_expression): Check TREE_NO_WARNING.
+
 2016-11-16  Jason Merrill  <jason@redhat.com>
 
        PR c++/78373
index 9a5039f99557c77a1310831a1dec9deb269a2083..3ab0b68653280d4d0864f2557627b2000c551319 100644 (file)
@@ -4679,7 +4679,9 @@ cp_parser_fold_expression (cp_parser *parser, tree expr1)
   /* The operands of a fold-expression are cast-expressions, so binary or
      conditional expressions are not allowed.  We check this here to avoid
      tentative parsing.  */
-  if (is_binary_op (TREE_CODE (expr1)))
+  if (EXPR_P (expr1) && TREE_NO_WARNING (expr1))
+    /* OK, the expression was parenthesized.  */;
+  else if (is_binary_op (TREE_CODE (expr1)))
     error_at (location_of (expr1),
              "binary expression in operand of fold-expression");
   else if (TREE_CODE (expr1) == COND_EXPR)
diff --git a/gcc/testsuite/g++.dg/cpp1z/fold8.C b/gcc/testsuite/g++.dg/cpp1z/fold8.C
new file mode 100644 (file)
index 0000000..e27db7a
--- /dev/null
@@ -0,0 +1,15 @@
+// PR c++/68377
+// { dg-options -std=c++1z }
+
+struct Sink { } s;
+template <class T> Sink& operator<<(Sink&, const T&);
+
+template<class... Tx> 
+int f(Tx... xs) {
+  return ((xs+1) + ...);
+}
+
+int main() {
+  s << f(3,4,5) << "\n";
+  return 0;
+}