[gcc(refs/users/aoliva/heads/testbase)] c++: Handle multiple aggregate overloads [PR95319].

Alexandre Oliva aoliva@gcc.gnu.org
Tue Jun 2 12:16:43 GMT 2020


https://gcc.gnu.org/g:6efa97ea1d2fe6df1fbb9df78faaa2248a8618d7

commit 6efa97ea1d2fe6df1fbb9df78faaa2248a8618d7
Author: Jason Merrill <jason@redhat.com>
Date:   Wed May 27 10:27:25 2020 -0400

    c++: Handle multiple aggregate overloads [PR95319].
    
    Here, when considering the two 'insert' overloads, we look for aggregate
    conversions from the same initializer-list to B<3> or
    initializer_list<B<3>>.  But since my fix for reshape_init overhead on the
    PR14179 testcase we reshaped the initializer-list directly, leading to an
    error when we then tried to reshape it differently for the second overload.
    
    gcc/cp/ChangeLog:
    
            PR c++/95319
            * decl.c (reshape_init_array_1): Don't reuse in overload context.
    
    gcc/testsuite/ChangeLog:
    
            PR c++/95319
            * g++.dg/cpp0x/initlist-array12.C: New test.

Diff:
---
 gcc/cp/decl.c                                 |  4 +++-
 gcc/testsuite/g++.dg/cpp0x/initlist-array12.C | 24 ++++++++++++++++++++++++
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 5476965996b..56571e39570 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -6029,8 +6029,10 @@ reshape_init_array_1 (tree elt_type, tree max_index, reshape_iter *d,
 
   /* The initializer for an array is always a CONSTRUCTOR.  If this is the
      outermost CONSTRUCTOR and the element type is non-aggregate, we don't need
-     to build a new one.  */
+     to build a new one.  But don't reuse if not complaining; if this is
+     tentative, we might also reshape to another type (95319).  */
   bool reuse = (first_initializer_p
+		&& (complain & tf_error)
 		&& !CP_AGGREGATE_TYPE_P (elt_type)
 		&& !TREE_SIDE_EFFECTS (first_initializer_p));
   if (reuse)
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-array12.C b/gcc/testsuite/g++.dg/cpp0x/initlist-array12.C
new file mode 100644
index 00000000000..b012e7295d5
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist-array12.C
@@ -0,0 +1,24 @@
+// PR c++/95319
+// { dg-do compile { target c++11 } }
+
+namespace std {
+template <class> class initializer_list {
+  int *_M_array;
+  unsigned long _M_len;
+};
+template <int _Nm> struct A { typedef int _Type[_Nm]; };
+template <int _Nm> struct B { typename A<_Nm>::_Type _M_elems; };
+class C {
+public:
+  void insert(int, B<3>);
+  void insert(int, initializer_list<B<3>>);
+};
+} // namespace std
+int a;
+int
+main() {
+  using ArrayVector = std::C;
+  auto b = ArrayVector();
+  b.insert(a, {{2}});
+  return 0;
+}


More information about the Gcc-cvs mailing list