diff mbox

C++ PATCH to unary fold-expression semantics

Message ID 56DF51B9.7010407@redhat.com
State New
Headers show

Commit Message

Jason Merrill March 8, 2016, 10:27 p.m. UTC
At Jacksonville the committee adjusted the semantics of C++17 
fold-expressions so that empty expansions are ill-formed for more 
operators.  Since this is a new feature in GCC 6, and the patch is 
trivial, let's update it accordingly.

Tested x86_64-pc-linux-gnu, applying to trunk.
diff mbox

Patch

commit d51e35e5c273c0706806777112e77ba395f0070d
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Mar 4 22:27:42 2016 -0500

    	P0036R0: Unary Folds and Empty Parameter Packs
    
    	* pt.c (expand_empty_fold): Remove special cases for *,+,&,|.

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 515537b..9766668 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -10629,10 +10629,6 @@  gen_elem_of_pack_expansion_instantiation (tree pattern,
    sequence, the value of the expression is as follows; the program is
    ill-formed if the operator is not listed in this table.
 
-   *	1
-   +	0
-   &	-1
-   |	0
    &&	true
    ||	false
    ,	void()  */
@@ -10644,14 +10640,6 @@  expand_empty_fold (tree t, tsubst_flags_t complain)
   if (!FOLD_EXPR_MODIFY_P (t))
     switch (code)
       {
-      case MULT_EXPR:
-	return integer_one_node;
-      case PLUS_EXPR:
-	return integer_zero_node;
-      case BIT_AND_EXPR:
-	return integer_minus_one_node;
-      case BIT_IOR_EXPR:
-	return integer_zero_node;
       case TRUTH_ANDIF_EXPR:
 	return boolean_true_node;
       case TRUTH_ORIF_EXPR:
diff --git a/gcc/testsuite/g++.dg/cpp1z/fold1.C b/gcc/testsuite/g++.dg/cpp1z/fold1.C
index 3c33651..510d61a 100644
--- a/gcc/testsuite/g++.dg/cpp1z/fold1.C
+++ b/gcc/testsuite/g++.dg/cpp1z/fold1.C
@@ -22,11 +22,11 @@  MAKE_FNS (add, +);
 MAKE_FNS (sub, -);
 
 int main() {
-  assert(unary_left_add() == 0);
+  // assert(unary_left_add() == 0);
   assert(unary_left_add(1) == 1);
   assert(unary_left_add(1, 2, 3) == 6);
 
-  assert(unary_right_add() == 0);
+  // assert(unary_right_add() == 0);
   assert(unary_right_add(1) == 1);
   assert(unary_right_add(1, 2, 3) == 6);
 
diff --git a/gcc/testsuite/g++.dg/cpp1z/fold3.C b/gcc/testsuite/g++.dg/cpp1z/fold3.C
index 307818f..58d41e6 100644
--- a/gcc/testsuite/g++.dg/cpp1z/fold3.C
+++ b/gcc/testsuite/g++.dg/cpp1z/fold3.C
@@ -47,16 +47,16 @@  MAKE_FN (dot_star, .*);
 MAKE_FN (arrow_star, ->*);
 
 int main() {
-  static_assert(add() == int(), "");
-  static_assert(mul() == 1, "");
-  static_assert(bor() == int(), "");
-  static_assert(band() == -1, "");
   static_assert(land() == true, "");
   static_assert(lor() == false, "");
   comma(); // No value to theck
 
   // These are all errors, but the error is emitted at the point
   // of instantiation (line 10).
+  add();			// { dg-message "required from here" }
+  mul();			// { dg-message "required from here" }
+  bor();			// { dg-message "required from here" }
+  band();			// { dg-message "required from here" }
   sub();			// { dg-message "required from here" }
   div();			// { dg-message "required from here" }
   mod();			// { dg-message "required from here" }