Patchwork C++ PATCH for c++/50054 (ICE after error with init-list)

login
register
mail settings
Submitter Jason Merrill
Date Aug. 16, 2011, 11:17 p.m.
Message ID <4E4AFA77.4070303@redhat.com>
Download mbox | patch
Permalink /patch/110250/
State New
Headers show

Comments

Jason Merrill - Aug. 16, 2011, 11:17 p.m.
It is possible to run into a situation where we don't know what to do 
with an initializer-list.

Tested x86_64-pc-linux-gnu, applying to trunk and 4.6.

Patch

commit 1a54ca9d63f7e6453b3327a5699a39696f856a79
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Aug 15 06:15:17 2011 -0400

    	PR c++/50054
    	* typeck2.c (cxx_incomplete_type_diagnostic): Handle
    	init_list_type_node.

diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c
index 0788138..79aa354 100644
--- a/gcc/cp/typeck2.c
+++ b/gcc/cp/typeck2.c
@@ -450,6 +450,12 @@  cxx_incomplete_type_diagnostic (const_tree value, const_tree type,
       break;
 
     case LANG_TYPE:
+      if (type == init_list_type_node)
+	{
+	  emit_diagnostic (diag_kind, input_location, 0,
+			   "invalid use of brace-enclosed initializer list");
+	  break;
+	}
       gcc_assert (type == unknown_type_node);
       if (value && TREE_CODE (value) == COMPONENT_REF)
 	goto bad_member;
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist57.C b/gcc/testsuite/g++.dg/cpp0x/initlist57.C
new file mode 100644
index 0000000..d945a46
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist57.C
@@ -0,0 +1,8 @@ 
+// PR c++/50054
+// { dg-options -std=c++0x }
+
+void g( const int& (a)[1] ) {}	// { dg-error "array of references" }
+
+int main () {
+    g( { 1, 2 } );		// { dg-error "initializer list" }
+}