This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C++ PATCH for c++/52905 (ICE with invalid list-initialization)


When a list-initialization doesn't quite match either a list constructor or a non-list constructor, we end up trying to compare them in joust and get confused because they have different numbers of parameters. So let's just treat them as unordered; we're going to talk about what's wrong with both of them anyway.

Tested x86_64-pc-linux-gnu, applying to trunk.
commit fad09b389b18d6f375b07bb680abc7e4590ecae2
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Apr 13 13:01:59 2012 -0400

    	PR c++/52905
    	* call.c (joust): Handle comparing list and non-list ctors.

diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 3c3dabb..46ac55c 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -8011,6 +8011,12 @@ joust (struct z_candidate *cand1, struct z_candidate *cand2, bool warn)
       int static_1 = DECL_STATIC_FUNCTION_P (cand1->fn);
       int static_2 = DECL_STATIC_FUNCTION_P (cand2->fn);
 
+      if (DECL_CONSTRUCTOR_P (cand1->fn)
+	  && is_list_ctor (cand1->fn) != is_list_ctor (cand2->fn))
+	/* We're comparing a near-match list constructor and a near-match
+	   non-list constructor.  Just treat them as unordered.  */
+	return 0;
+
       gcc_assert (static_1 != static_2);
 
       if (static_1)
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-ctor1.C b/gcc/testsuite/g++.dg/cpp0x/initlist-ctor1.C
new file mode 100644
index 0000000..82031cb
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist-ctor1.C
@@ -0,0 +1,13 @@
+// PR c++/52905
+// { dg-options -std=c++11 }
+
+#include <initializer_list>
+
+enum E { e1, e2 };
+struct A
+{
+  A(std::initializer_list<E>);	// { dg-message "A::A" }
+  A(int, E);			// { dg-message "A::A" }
+};
+
+A a{e1,2};			// { dg-error "" }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]