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++/38380


My initial initializer-list patch stopped setting DECL_NONCONVERTING_P on constructors taking multiple arguments, but it didn't occur to me then that we also need to stop setting it on 0-argument constructors to support conversion from { }. Also, the distinction between direct- and copy-list-initialization was getting lost in templates.

Tested x86_64-pc-linux-gnu, applied to trunk.

2008-12-03  Jason Merrill  <jason@redhat.com>

	PR c++/38380
	* decl.c (grokdeclarator): Only set DECL_NONCONVERTING_P
	on explicit constructors.
	* pt.c (tsubst_copy_and_build) [CONSTRUCTOR]: Propagate
	CONSTRUCTOR_IS_DIRECT_INIT.
	* g++.dg/cpp0x/initlist10.C: New test.
	* g++.old-deja/g++.eh/ctor1.C: Default ctor is a candidate too.
	* g++.dg/tc1/dr152.C: Likewise.

Index: cp/decl.c
===================================================================
*** cp/decl.c	(revision 142379)
--- cp/decl.c	(working copy)
*************** grokdeclarator (const cp_declarator *dec
*** 9099,9113 ****
  	       is called a converting constructor.  */
  	    if (explicitp == 2)
  	      DECL_NONCONVERTING_P (decl) = 1;
- 	    else if (DECL_CONSTRUCTOR_P (decl))
- 	      {
- 		/* A constructor with no parms is not a conversion.
- 		   Ignore any compiler-added parms.  */
- 		tree arg_types = FUNCTION_FIRST_USER_PARMTYPE (decl);
- 
- 		if (arg_types == void_list_node)
- 		  DECL_NONCONVERTING_P (decl) = 1;
- 	      }
  	  }
  	else if (TREE_CODE (type) == METHOD_TYPE)
  	  {
--- 9099,9104 ----
Index: cp/pt.c
===================================================================
*** cp/pt.c	(revision 142371)
--- cp/pt.c	(working copy)
*************** tsubst_copy_and_build (tree t,
*** 11612,11617 ****
--- 11612,11618 ----
            }
  
  	r = build_constructor (init_list_type_node, n);
+ 	CONSTRUCTOR_IS_DIRECT_INIT (r) = CONSTRUCTOR_IS_DIRECT_INIT (t);
  
  	if (TREE_HAS_CONSTRUCTOR (t))
  	  return finish_compound_literal (type, r);
Index: testsuite/g++.old-deja/g++.eh/ctor1.C
===================================================================
*** testsuite/g++.old-deja/g++.eh/ctor1.C	(revision 142371)
--- testsuite/g++.old-deja/g++.eh/ctor1.C	(working copy)
***************
*** 1,7 ****
  // { dg-do assemble  }
  struct A
  {
!   A();
    A(A&);			// { dg-message "candidates" } referenced below
  };
  
--- 1,7 ----
  // { dg-do assemble  }
  struct A
  {
!   A();				// { dg-message "" } candidate
    A(A&);			// { dg-message "candidates" } referenced below
  };
  
Index: testsuite/g++.dg/tc1/dr152.C
===================================================================
*** testsuite/g++.dg/tc1/dr152.C	(revision 142371)
--- testsuite/g++.dg/tc1/dr152.C	(working copy)
***************
*** 4,10 ****
  
  namespace N1 {
    struct X {
!     X();
      explicit X(const X&);
    };
    void f(X);
--- 4,10 ----
  
  namespace N1 {
    struct X {
!     X();			// { dg-message "candidate" }
      explicit X(const X&);
    };
    void f(X);
*************** namespace N1 {
*** 19,25 ****
  namespace N2 {
    template <class T>
    struct X {
!     X();
      explicit X(const X&);
    };
  
--- 19,25 ----
  namespace N2 {
    template <class T>
    struct X {
!     X();			// { dg-message "candidate" }
      explicit X(const X&);
    };
  
Index: testsuite/g++.dg/cpp0x/initlist10.C
===================================================================
*** testsuite/g++.dg/cpp0x/initlist10.C	(revision 0)
--- testsuite/g++.dg/cpp0x/initlist10.C	(revision 0)
***************
*** 0 ****
--- 1,53 ----
+ // PR c++/38380
+ // { dg-options "-std=gnu++0x" }
+ 
+ namespace std
+ {
+  struct atomic_bool
+   {
+     bool _M_i;
+ 
+     atomic_bool() = default;
+     ~atomic_bool() = default;
+     atomic_bool(const atomic_bool&) = delete;
+     atomic_bool& operator=(const atomic_bool&) = delete;
+ 
+     explicit atomic_bool(bool __i) { _M_i = __i; }
+ 
+     operator bool() const volatile
+     { return true; }
+   };
+ }
+ 
+ namespace __gnu_test
+ {
+   struct direct_list_initializable
+   {
+     template<typename _Ttype, typename _Tvalue>
+       void 
+       operator()()
+       {
+         struct _Concept
+         {
+           void __constraint()
+           { 
+             _Ttype __v1 = { }; // default ctor
+             _Ttype __v2 { __a };  // single-argument ctor
+           }
+ 
+           _Tvalue __a;
+         };
+ 
+         void (_Concept::*__x)() __attribute__((unused))
+           = &_Concept::__constraint;
+       }
+   };
+ }
+ 
+ int main()
+ {
+   __gnu_test::direct_list_initializable test;
+ 
+   test.operator()<std::atomic_bool, bool>();
+   return 0;
+ }

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