diff mbox

C++ PATCH for c++/80415, wrong error with default arg and array reference

Message ID CADzB+2kqh1ULfnQ1KW7=NDUQNMKTA+MjED+n0qYKPLdhJz-isQ@mail.gmail.com
State New
Headers show

Commit Message

Jason Merrill April 17, 2017, 7:26 p.m. UTC
Here, converting the default argument to the array type produces a
typed CONSTRUCTOR, which we later fail to bind directly to the
reference parameter.  We should treat this kind of array prvalue the
same way we do class prvalues.

Tested x86_64-pc-linux-gnu, applying to trunk.
commit 4c11ceffefdba2652f7eb8c20ce6b0a4c7436ee9
Author: Jason Merrill <jason@redhat.com>
Date:   Thu Apr 13 16:28:55 2017 -0400

            PR c++/80415 - wrong error with default arg and array reference.
    
            * tree.c (lvalue_kind): Return clk_class for an array prvalue.
diff mbox

Patch

diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 57c1401..67dfea2 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -4677,7 +4677,7 @@  enum cp_lvalue_kind_flags {
   clk_none = 0,     /* Things that are not an lvalue.  */
   clk_ordinary = 1, /* An ordinary lvalue.  */
   clk_rvalueref = 2,/* An xvalue (rvalue formed using an rvalue reference) */
-  clk_class = 4,    /* A prvalue of class-type.  */
+  clk_class = 4,    /* A prvalue of class or array type.  */
   clk_bitfield = 8, /* An lvalue for a bit-field.  */
   clk_packed = 16   /* An lvalue for a packed field.  */
 };
diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index 2edd567..a1455c2 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -243,7 +243,8 @@  lvalue_kind (const_tree ref)
     default:
       if (!TREE_TYPE (ref))
 	return clk_none;
-      if (CLASS_TYPE_P (TREE_TYPE (ref)))
+      if (CLASS_TYPE_P (TREE_TYPE (ref))
+	  || TREE_CODE (TREE_TYPE (ref)) == ARRAY_TYPE)
 	return clk_class;
       break;
     }
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-array5.C b/gcc/testsuite/g++.dg/cpp0x/initlist-array5.C
new file mode 100644
index 0000000..12080a0
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist-array5.C
@@ -0,0 +1,7 @@ 
+// PR c++/80415
+// { dg-do compile { target c++11 } }
+
+struct A {
+  A(int, int, const int (&)[1] = {});
+};
+A fn1() { return {0, 0}; }