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 to unification of initializer lists


My implementation of deduction from an initializer list wasn't doing the normal adjustment of argument/parameter types for deduction from a call, which prevents deduction of initializer_list<const char *> from a list of C strings. Fixed thus.

Tested x86_64-pc-linux-gnu. I'm applying to trunk because this is the reference implementation of this feature for the C++0x standardization committee, and it doesn't affect code that doesn't use initializer lists.
2009-02-22  Jason Merrill  <jason@redhat.com>

	* pt.c (unify): Call maybe_adjust_types_for_deduction when
	deducing from an initializer list.

Index: cp/pt.c
===================================================================
*** cp/pt.c	(revision 144376)
--- cp/pt.c	(working copy)
*************** unify (tree tparms, tree targs, tree par
*** 13204,13212 ****
  
        FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (arg), i, elt)
  	{
  	  if (!BRACE_ENCLOSED_INITIALIZER_P (elt))
! 	    elt = TREE_TYPE (elt);
! 	  if (unify (tparms, targs, elttype, elt, UNIFY_ALLOW_NONE))
  	    return 1;
  	}
        return 0;
--- 13204,13221 ----
  
        FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (arg), i, elt)
  	{
+ 	  int elt_strict = strict;
  	  if (!BRACE_ENCLOSED_INITIALIZER_P (elt))
! 	    {
! 	      tree type = TREE_TYPE (elt);
! 	      /* It should only be possible to get here for a call.  */
! 	      gcc_assert (elt_strict & UNIFY_ALLOW_OUTER_LEVEL);
! 	      elt_strict |= maybe_adjust_types_for_deduction
! 		(DEDUCE_CALL, &elttype, &type, elt);
! 	      elt = type;
! 	    }
! 
! 	  if (unify (tparms, targs, elttype, elt, elt_strict))
  	    return 1;
  	}
        return 0;
Index: testsuite/g++.dg/cpp0x/initlist14.C
===================================================================
*** testsuite/g++.dg/cpp0x/initlist14.C	(revision 0)
--- testsuite/g++.dg/cpp0x/initlist14.C	(revision 0)
***************
*** 0 ****
--- 1,19 ----
+ // Bug: We weren't doing the normal replacement of array with pointer
+ // for deduction in the context of a call because of the initializer list.
+ // { dg-options "-std=c++0x" }
+ 
+ #include <initializer_list>
+ 
+ struct string
+ {
+   string (const char *);
+ };
+ 
+ template <class T>
+ struct vector
+ {
+   template <class U>
+   vector (std::initializer_list<U>);
+ };
+ 
+ vector<string> v = { "a", "b", "c" };

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