public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ PATCH] For -std=c++1z treat class types with inherited ctors as non-aggregate (PR c++/79143)
@ 2017-02-07 21:30 Jakub Jelinek
  2017-02-08 21:52 ` Jason Merrill
  0 siblings, 1 reply; 6+ messages in thread
From: Jakub Jelinek @ 2017-02-07 21:30 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches

Hi!

P0017R1 added in [dcl.init.aggr]/1 that classes with inherited constructors
are not aggregate.  CLASSTYPE_NON_AGGREGATE is set slightly before
add_implicitly_declared_members is called and so we don't know about the
inherited ctors yet.

Not 100% sure if we want to do this even for -std=c++1z
-fno-new-inheriting-ctors (i.e. if the below block shouldn't be guarded with
&& flag_new_inheriting_ctors too), because e.g. for
-fno-new-inheriting-ctors we actually don't set TYPE_HAS_USER_CONSTRUCTOR.

Bootstrapped/regtested on x86_64-linux and i686-linux and additionally
tested with make check-c++-all on both.

2017-02-07  Jakub Jelinek  <jakub@redhat.com>

	PR c++/79143
	* class.c (add_implicitly_declared_members): Set
	CLASSTYPE_NON_AGGREGATE and CLASSTYPE_NON_LAYOUT_POD_P on types
	with inherited constructors for C++17.

	* g++.dg/cpp1z/pr79143.C: New test.

--- gcc/cp/class.c.jj	2017-02-04 08:43:15.000000000 +0100
+++ gcc/cp/class.c	2017-02-07 18:00:24.479093367 +0100
@@ -3453,8 +3453,19 @@ add_implicitly_declared_members (tree t,
 	  location_t loc = input_location;
 	  input_location = DECL_SOURCE_LOCATION (using_decl);
 	  if (ctor_list)
-	    for (; ctor_list; ctor_list = OVL_NEXT (ctor_list))
-	      one_inherited_ctor (OVL_CURRENT (ctor_list), t, using_decl);
+	    {
+	      if (cxx_dialect >= cxx1z)
+		{
+		  /* [dcl.init.aggr]/1: An aggregate is an array or a class
+		     with
+		     - no user-provided, explicit or inherited
+		       constructors.  */
+		  CLASSTYPE_NON_AGGREGATE (t) = 1;
+		  CLASSTYPE_NON_LAYOUT_POD_P (t) = 1;
+		}
+	      for (; ctor_list; ctor_list = OVL_NEXT (ctor_list))
+		one_inherited_ctor (OVL_CURRENT (ctor_list), t, using_decl);
+	    }
 	  *access_decls = TREE_CHAIN (*access_decls);
 	  input_location = loc;
 	}
--- gcc/testsuite/g++.dg/cpp1z/pr79143.C.jj	2017-02-07 17:55:19.091028200 +0100
+++ gcc/testsuite/g++.dg/cpp1z/pr79143.C	2017-02-07 17:54:48.000000000 +0100
@@ -0,0 +1,28 @@
+// PR c++/79143
+// { dg-do compile }
+// { dg-options "-std=c++1z" }
+
+struct base {
+  base (int, int) {}
+};
+
+template<class>
+struct derived : base {
+  using base::base;
+};
+
+template<class>
+struct derived2 : base {
+  derived2 (int x, int y) : base (x, y) {}
+};
+
+int
+main ()
+{
+  base (13, 42);
+  derived<int> (13, 42);
+  derived2<int> (13, 42);
+  base{13, 42};
+  derived<int>{13, 42}; // { dg-bogus "too many initializers" }
+  derived2<int>{13, 42};
+}

	Jakub

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [C++ PATCH] For -std=c++1z treat class types with inherited ctors as non-aggregate (PR c++/79143)
  2017-02-07 21:30 [C++ PATCH] For -std=c++1z treat class types with inherited ctors as non-aggregate (PR c++/79143) Jakub Jelinek
@ 2017-02-08 21:52 ` Jason Merrill
  2017-02-08 22:24   ` Jakub Jelinek
  0 siblings, 1 reply; 6+ messages in thread
From: Jason Merrill @ 2017-02-08 21:52 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches List

On Tue, Feb 7, 2017 at 4:30 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> P0017R1 added in [dcl.init.aggr]/1 that classes with inherited constructors
> are not aggregate.  CLASSTYPE_NON_AGGREGATE is set slightly before
> add_implicitly_declared_members is called and so we don't know about the
> inherited ctors yet.

Hmm, why doesn't my patch for 78124 to set CLASSTYPE_NON_AGGREGATE in
do_class_using_decl cover this testcase?

Jason

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [C++ PATCH] For -std=c++1z treat class types with inherited ctors as non-aggregate (PR c++/79143)
  2017-02-08 21:52 ` Jason Merrill
@ 2017-02-08 22:24   ` Jakub Jelinek
  2017-02-08 23:47     ` Jason Merrill
  0 siblings, 1 reply; 6+ messages in thread
From: Jakub Jelinek @ 2017-02-08 22:24 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches List

On Wed, Feb 08, 2017 at 04:51:54PM -0500, Jason Merrill wrote:
> On Tue, Feb 7, 2017 at 4:30 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> > P0017R1 added in [dcl.init.aggr]/1 that classes with inherited constructors
> > are not aggregate.  CLASSTYPE_NON_AGGREGATE is set slightly before
> > add_implicitly_declared_members is called and so we don't know about the
> > inherited ctors yet.
> 
> Hmm, why doesn't my patch for 78124 to set CLASSTYPE_NON_AGGREGATE in
> do_class_using_decl cover this testcase?

It does set CLASSTYPE_NON_AGGREGATE on a different RECORD_TYPE,
do_class_using_decl sees the template, while what is tested and what
check_bases_and_members is called on is the implicit instantiation thereof.

The following completely untested patch also fixes it.  Or is there some
even better place where to copy over that bit from the template to the
instantiation?

2017-02-08  Jakub Jelinek  <jakub@redhat.com>

	PR c++/79143
	* pt.c (lookup_template_class_1): Copy CLASSTYPE_NON_AGGREGATE
	from template_type to t.

	* g++.dg/cpp1z/pr79143.C: New test.

--- gcc/cp/pt.c.jj	2017-02-06 21:02:40.000000000 +0100
+++ gcc/cp/pt.c	2017-02-08 23:18:20.461836658 +0100
@@ -8770,6 +8770,8 @@ lookup_template_class_1 (tree d1, tree a
 	  t = make_class_type (TREE_CODE (template_type));
 	  CLASSTYPE_DECLARED_CLASS (t)
 	    = CLASSTYPE_DECLARED_CLASS (template_type);
+	  CLASSTYPE_NON_AGGREGATE (t)
+	    = CLASSTYPE_NON_AGGREGATE (template_type);
 	  SET_CLASSTYPE_IMPLICIT_INSTANTIATION (t);
 
 	  /* A local class.  Make sure the decl gets registered properly.  */
--- gcc/testsuite/g++.dg/cpp1z/pr79143.C.jj	2017-02-07 17:55:19.091028200 +0100
+++ gcc/testsuite/g++.dg/cpp1z/pr79143.C	2017-02-07 17:54:48.000000000 +0100
@@ -0,0 +1,28 @@
+// PR c++/79143
+// { dg-do compile }
+// { dg-options "-std=c++1z" }
+
+struct base {
+  base (int, int) {}
+};
+
+template<class>
+struct derived : base {
+  using base::base;
+};
+
+template<class>
+struct derived2 : base {
+  derived2 (int x, int y) : base (x, y) {}
+};
+
+int
+main ()
+{
+  base (13, 42);
+  derived<int> (13, 42);
+  derived2<int> (13, 42);
+  base{13, 42};
+  derived<int>{13, 42}; // { dg-bogus "too many initializers" }
+  derived2<int>{13, 42};
+}


	Jakub

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [C++ PATCH] For -std=c++1z treat class types with inherited ctors as non-aggregate (PR c++/79143)
  2017-02-08 22:24   ` Jakub Jelinek
@ 2017-02-08 23:47     ` Jason Merrill
  2017-02-09 14:16       ` [C++ PATCH] For -std=c++1z treat class types with inherited ctors as non-aggregate (PR c++/79143, take 3) Jakub Jelinek
  0 siblings, 1 reply; 6+ messages in thread
From: Jason Merrill @ 2017-02-08 23:47 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches List

On Wed, Feb 8, 2017 at 5:24 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> On Wed, Feb 08, 2017 at 04:51:54PM -0500, Jason Merrill wrote:
>> On Tue, Feb 7, 2017 at 4:30 PM, Jakub Jelinek <jakub@redhat.com> wrote:
>> > P0017R1 added in [dcl.init.aggr]/1 that classes with inherited constructors
>> > are not aggregate.  CLASSTYPE_NON_AGGREGATE is set slightly before
>> > add_implicitly_declared_members is called and so we don't know about the
>> > inherited ctors yet.
>>
>> Hmm, why doesn't my patch for 78124 to set CLASSTYPE_NON_AGGREGATE in
>> do_class_using_decl cover this testcase?
>
> It does set CLASSTYPE_NON_AGGREGATE on a different RECORD_TYPE,
> do_class_using_decl sees the template, while what is tested and what
> check_bases_and_members is called on is the implicit instantiation thereof.
>
> The following completely untested patch also fixes it.  Or is there some
> even better place where to copy over that bit from the template to the
> instantiation?

Better I think in instantiate_class_template_1, about where we copy TYPE_PACKED.

Jason

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [C++ PATCH] For -std=c++1z treat class types with inherited ctors as non-aggregate (PR c++/79143, take 3)
  2017-02-08 23:47     ` Jason Merrill
@ 2017-02-09 14:16       ` Jakub Jelinek
  2017-02-09 21:49         ` Jason Merrill
  0 siblings, 1 reply; 6+ messages in thread
From: Jakub Jelinek @ 2017-02-09 14:16 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches List

On Wed, Feb 08, 2017 at 06:47:10PM -0500, Jason Merrill wrote:
> On Wed, Feb 8, 2017 at 5:24 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> > On Wed, Feb 08, 2017 at 04:51:54PM -0500, Jason Merrill wrote:
> >> On Tue, Feb 7, 2017 at 4:30 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> >> > P0017R1 added in [dcl.init.aggr]/1 that classes with inherited constructors
> >> > are not aggregate.  CLASSTYPE_NON_AGGREGATE is set slightly before
> >> > add_implicitly_declared_members is called and so we don't know about the
> >> > inherited ctors yet.
> >>
> >> Hmm, why doesn't my patch for 78124 to set CLASSTYPE_NON_AGGREGATE in
> >> do_class_using_decl cover this testcase?
> >
> > It does set CLASSTYPE_NON_AGGREGATE on a different RECORD_TYPE,
> > do_class_using_decl sees the template, while what is tested and what
> > check_bases_and_members is called on is the implicit instantiation thereof.
> >
> > The following completely untested patch also fixes it.  Or is there some
> > even better place where to copy over that bit from the template to the
> > instantiation?
> 
> Better I think in instantiate_class_template_1, about where we copy TYPE_PACKED.

That works too, bootstrapped/regtested on x86_64-linux and i686-linux, ok
for trunk?

2017-02-09  Jakub Jelinek  <jakub@redhat.com>
	    Jason Merrill  <jason@redhat.com>

	PR c++/79143
	* pt.c (instantiate_class_template_1): Copy CLASSTYPE_NON_AGGREGATE
	from pattern to type.

	* g++.dg/cpp1z/pr79143.C: New test.

--- gcc/cp/pt.c.jj	2017-02-06 21:02:40.000000000 +0100
+++ gcc/cp/pt.c	2017-02-09 00:57:58.961930210 +0100
@@ -10253,6 +10253,7 @@ instantiate_class_template_1 (tree type)
   TYPE_PACKED (type) = TYPE_PACKED (pattern);
   SET_TYPE_ALIGN (type, TYPE_ALIGN (pattern));
   TYPE_USER_ALIGN (type) = TYPE_USER_ALIGN (pattern);
+  CLASSTYPE_NON_AGGREGATE (type) = CLASSTYPE_NON_AGGREGATE (pattern);
   if (ANON_AGGR_TYPE_P (pattern))
     SET_ANON_AGGR_TYPE_P (type);
   if (CLASSTYPE_VISIBILITY_SPECIFIED (pattern))
--- gcc/testsuite/g++.dg/cpp1z/pr79143.C.jj	2017-02-07 17:55:19.091028200 +0100
+++ gcc/testsuite/g++.dg/cpp1z/pr79143.C	2017-02-07 17:54:48.000000000 +0100
@@ -0,0 +1,28 @@
+// PR c++/79143
+// { dg-do compile }
+// { dg-options "-std=c++1z" }
+
+struct base {
+  base (int, int) {}
+};
+
+template<class>
+struct derived : base {
+  using base::base;
+};
+
+template<class>
+struct derived2 : base {
+  derived2 (int x, int y) : base (x, y) {}
+};
+
+int
+main ()
+{
+  base (13, 42);
+  derived<int> (13, 42);
+  derived2<int> (13, 42);
+  base{13, 42};
+  derived<int>{13, 42}; // { dg-bogus "too many initializers" }
+  derived2<int>{13, 42};
+}


	Jakub

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [C++ PATCH] For -std=c++1z treat class types with inherited ctors as non-aggregate (PR c++/79143, take 3)
  2017-02-09 14:16       ` [C++ PATCH] For -std=c++1z treat class types with inherited ctors as non-aggregate (PR c++/79143, take 3) Jakub Jelinek
@ 2017-02-09 21:49         ` Jason Merrill
  0 siblings, 0 replies; 6+ messages in thread
From: Jason Merrill @ 2017-02-09 21:49 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches List

OK.

On Thu, Feb 9, 2017 at 9:16 AM, Jakub Jelinek <jakub@redhat.com> wrote:
> On Wed, Feb 08, 2017 at 06:47:10PM -0500, Jason Merrill wrote:
>> On Wed, Feb 8, 2017 at 5:24 PM, Jakub Jelinek <jakub@redhat.com> wrote:
>> > On Wed, Feb 08, 2017 at 04:51:54PM -0500, Jason Merrill wrote:
>> >> On Tue, Feb 7, 2017 at 4:30 PM, Jakub Jelinek <jakub@redhat.com> wrote:
>> >> > P0017R1 added in [dcl.init.aggr]/1 that classes with inherited constructors
>> >> > are not aggregate.  CLASSTYPE_NON_AGGREGATE is set slightly before
>> >> > add_implicitly_declared_members is called and so we don't know about the
>> >> > inherited ctors yet.
>> >>
>> >> Hmm, why doesn't my patch for 78124 to set CLASSTYPE_NON_AGGREGATE in
>> >> do_class_using_decl cover this testcase?
>> >
>> > It does set CLASSTYPE_NON_AGGREGATE on a different RECORD_TYPE,
>> > do_class_using_decl sees the template, while what is tested and what
>> > check_bases_and_members is called on is the implicit instantiation thereof.
>> >
>> > The following completely untested patch also fixes it.  Or is there some
>> > even better place where to copy over that bit from the template to the
>> > instantiation?
>>
>> Better I think in instantiate_class_template_1, about where we copy TYPE_PACKED.
>
> That works too, bootstrapped/regtested on x86_64-linux and i686-linux, ok
> for trunk?
>
> 2017-02-09  Jakub Jelinek  <jakub@redhat.com>
>             Jason Merrill  <jason@redhat.com>
>
>         PR c++/79143
>         * pt.c (instantiate_class_template_1): Copy CLASSTYPE_NON_AGGREGATE
>         from pattern to type.
>
>         * g++.dg/cpp1z/pr79143.C: New test.
>
> --- gcc/cp/pt.c.jj      2017-02-06 21:02:40.000000000 +0100
> +++ gcc/cp/pt.c 2017-02-09 00:57:58.961930210 +0100
> @@ -10253,6 +10253,7 @@ instantiate_class_template_1 (tree type)
>    TYPE_PACKED (type) = TYPE_PACKED (pattern);
>    SET_TYPE_ALIGN (type, TYPE_ALIGN (pattern));
>    TYPE_USER_ALIGN (type) = TYPE_USER_ALIGN (pattern);
> +  CLASSTYPE_NON_AGGREGATE (type) = CLASSTYPE_NON_AGGREGATE (pattern);
>    if (ANON_AGGR_TYPE_P (pattern))
>      SET_ANON_AGGR_TYPE_P (type);
>    if (CLASSTYPE_VISIBILITY_SPECIFIED (pattern))
> --- gcc/testsuite/g++.dg/cpp1z/pr79143.C.jj     2017-02-07 17:55:19.091028200 +0100
> +++ gcc/testsuite/g++.dg/cpp1z/pr79143.C        2017-02-07 17:54:48.000000000 +0100
> @@ -0,0 +1,28 @@
> +// PR c++/79143
> +// { dg-do compile }
> +// { dg-options "-std=c++1z" }
> +
> +struct base {
> +  base (int, int) {}
> +};
> +
> +template<class>
> +struct derived : base {
> +  using base::base;
> +};
> +
> +template<class>
> +struct derived2 : base {
> +  derived2 (int x, int y) : base (x, y) {}
> +};
> +
> +int
> +main ()
> +{
> +  base (13, 42);
> +  derived<int> (13, 42);
> +  derived2<int> (13, 42);
> +  base{13, 42};
> +  derived<int>{13, 42}; // { dg-bogus "too many initializers" }
> +  derived2<int>{13, 42};
> +}
>
>
>         Jakub

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-02-09 21:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-07 21:30 [C++ PATCH] For -std=c++1z treat class types with inherited ctors as non-aggregate (PR c++/79143) Jakub Jelinek
2017-02-08 21:52 ` Jason Merrill
2017-02-08 22:24   ` Jakub Jelinek
2017-02-08 23:47     ` Jason Merrill
2017-02-09 14:16       ` [C++ PATCH] For -std=c++1z treat class types with inherited ctors as non-aggregate (PR c++/79143, take 3) Jakub Jelinek
2017-02-09 21:49         ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).