Patchwork C++ PATCH for c++/44703 (initializer_list typedef)

login
register
mail settings
Submitter Jason Merrill
Date July 6, 2010, 7:22 p.m.
Message ID <4C33825D.4080308@redhat.com>
Download mbox | patch
Permalink /patch/58057/
State New
Headers show

Comments

Jason Merrill - July 6, 2010, 7:22 p.m.
Need to look through typedefs if we're doing matching on names...

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

Patch

commit f7a5840c46397ad2e75b9f3a47219d697a75bccf
Author: Jason Merrill <jason@redhat.com>
Date:   Sun Jul 4 09:57:42 2010 -0400

    	PR c++/44703
    	* call.c (is_std_init_list): Look through typedefs.

diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index c4f3e95..0bf7b8e 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -7953,6 +7953,10 @@  initialize_reference (tree type, tree expr, tree decl, tree *cleanup,
 bool
 is_std_init_list (tree type)
 {
+  /* Look through typedefs.  */
+  if (!TYPE_P (type))
+    return false;
+  type = TYPE_MAIN_VARIANT (type);
   return (CLASS_TYPE_P (type)
 	  && CP_TYPE_CONTEXT (type) == std_node
 	  && strcmp (TYPE_NAME_STRING (type), "initializer_list") == 0);
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist41.C b/gcc/testsuite/g++.dg/cpp0x/initlist41.C
new file mode 100644
index 0000000..b538548
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist41.C
@@ -0,0 +1,14 @@ 
+// PR c++/44703
+// { dg-options -std=c++0x }
+
+#include <initializer_list>
+
+typedef std::initializer_list<int> type ;
+void f(type) {}
+
+int main()
+{
+//  error: could not convert '{1, 2, 3}' to 'type'
+    f({1,2,3}) ;
+}
+