public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ PATCH for testsuite failures with -std=c++17
@ 2017-05-09 20:42 Jason Merrill
  2017-05-25  9:08 ` Jakub Jelinek
  0 siblings, 1 reply; 4+ messages in thread
From: Jason Merrill @ 2017-05-09 20:42 UTC (permalink / raw)
  To: gcc-patches List

[-- Attachment #1: Type: text/plain, Size: 277 bytes --]

For C++17 aggregate bases, we have started adding base fields for
empty bases.  The code for calculating whether a class is standard
layout needs to ignore these.

The C++17 mode diagnostic for direct-enum-init1.C was incorrect.

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

[-- Attachment #2: 1z-regr.diff --]
[-- Type: text/plain, Size: 2937 bytes --]

commit 9a612cc30d4b3ef905ce45304545d8b99a3cf5b9
Author: Jason Merrill <jason@redhat.com>
Date:   Tue May 9 14:15:38 2017 -0400

            * class.c (check_bases): Ignore empty bases.

diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index fc71766..085dbc3 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -1860,7 +1860,9 @@ check_bases (tree t,
 	       members */
 	    for (basefield = TYPE_FIELDS (basetype); basefield;
 		 basefield = DECL_CHAIN (basefield))
-	      if (TREE_CODE (basefield) == FIELD_DECL)
+	      if (TREE_CODE (basefield) == FIELD_DECL
+		  && DECL_SIZE (basefield)
+		  && !integer_zerop (DECL_SIZE (basefield)))
 		{
 		  if (field)
 		    CLASSTYPE_NON_STD_LAYOUT (t) = 1;
diff --git a/gcc/testsuite/g++.dg/ext/is_std_layout1.C b/gcc/testsuite/g++.dg/ext/is_std_layout1.C
new file mode 100644
index 0000000..007c94a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/is_std_layout1.C
@@ -0,0 +1,12 @@
+// { dg-do compile { target c++11 } }
+
+template <int> struct E { };
+
+struct E1: E<0>, E<1> { };
+struct E2: E<2>, E<3> { };
+
+struct A1x { int n; };
+struct D2: A1x, E1, E2 { };
+
+#define SA(X) static_assert((X),#X)
+SA(__is_standard_layout (D2));

commit 90bdd7df4aa641d53edacd20414d724babfe4af8
Author: Jason Merrill <jason@redhat.com>
Date:   Tue May 9 13:51:07 2017 -0400

            * g++.dg/cpp1z/direct-enum-init1.C: Correct error message.

diff --git a/gcc/testsuite/g++.dg/cpp1z/direct-enum-init1.C b/gcc/testsuite/g++.dg/cpp1z/direct-enum-init1.C
index a17473f..11269cc 100644
--- a/gcc/testsuite/g++.dg/cpp1z/direct-enum-init1.C
+++ b/gcc/testsuite/g++.dg/cpp1z/direct-enum-init1.C
@@ -22,7 +22,7 @@ foo ()
   C c1 { s };
   D d1 { D(t) };	// { dg-error "invalid cast from type 'T' to type 'D {enum}'" }
   D d2 { t };		// { dg-error "cannot convert 'T' to 'D {enum}' in initialization" "" { target c++14_down } }
-			// { dg-error "invalid cast from type 'T' to type 'D'" "" { target c++1z } .-1 }
+			// { dg-error "invalid cast from type 'T' to type 'D {enum}'" "" { target c++1z } .-1 }
   D d3 { 9 };		// { dg-error "cannot convert 'int' to 'D {enum}' in initialization" "" { target c++14_down } }
   D d4 { l };		// { dg-error "cannot convert 'long int' to 'D {enum}' in initialization" "" { target c++14_down } }
   D d5 { D(l) };
@@ -89,7 +89,7 @@ foo2 ()
   C c1 { s };
   D d1 { D(t) };	// { dg-error "invalid cast from type 'T' to type 'D {enum}'" }
   D d2 { t };		// { dg-error "cannot convert 'T' to 'D {enum}' in initialization" "" { target c++14_down } }
-			// { dg-error "invalid cast from type 'T' to type 'D'" "" { target c++1z } .-1 }
+			// { dg-error "invalid cast from type 'T' to type 'D {enum}'" "" { target c++1z } .-1 }
   D d3 { 9 };		// { dg-error "cannot convert 'int' to 'D {enum}' in initialization" "" { target c++14_down } }
   D d4 { l };		// { dg-error "cannot convert 'long int' to 'D {enum}' in initialization" "" { target c++14_down } }
   D d5 { D(l) };

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

* Re: C++ PATCH for testsuite failures with -std=c++17
  2017-05-09 20:42 C++ PATCH for testsuite failures with -std=c++17 Jason Merrill
@ 2017-05-25  9:08 ` Jakub Jelinek
  2017-05-25  9:23   ` Jakub Jelinek
  0 siblings, 1 reply; 4+ messages in thread
From: Jakub Jelinek @ 2017-05-25  9:08 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches List

On Tue, May 09, 2017 at 04:37:16PM -0400, Jason Merrill wrote:
> For C++17 aggregate bases, we have started adding base fields for
> empty bases.  The code for calculating whether a class is standard
> layout needs to ignore these.
> 
> The C++17 mode diagnostic for direct-enum-init1.C was incorrect.
> 
> Tested x86_64-pc-linux-gnu, applying to trunk.

> commit 9a612cc30d4b3ef905ce45304545d8b99a3cf5b9
> Author: Jason Merrill <jason@redhat.com>
> Date:   Tue May 9 14:15:38 2017 -0400
> 
>             * class.c (check_bases): Ignore empty bases.

This should have referenced PR c++/80605 (and is also a 7 regression).

> diff --git a/gcc/cp/class.c b/gcc/cp/class.c
> index fc71766..085dbc3 100644
> --- a/gcc/cp/class.c
> +++ b/gcc/cp/class.c
> @@ -1860,7 +1860,9 @@ check_bases (tree t,
>  	       members */
>  	    for (basefield = TYPE_FIELDS (basetype); basefield;
>  		 basefield = DECL_CHAIN (basefield))
> -	      if (TREE_CODE (basefield) == FIELD_DECL)
> +	      if (TREE_CODE (basefield) == FIELD_DECL
> +		  && DECL_SIZE (basefield)
> +		  && !integer_zerop (DECL_SIZE (basefield)))

Is that what we really want?  I mean, shouldn't we at least also
check that the basefield we want to ignore is DECL_ARTIFICIAL,
or that it doesn't have DECL_NAME or something similar, to avoid
considering user fields with zero size the same?
I believe your change changes e.g.:
struct S { int a[0]; };
struct T : public S { int b[0]; int c; };
bool q = __is_standard_layout (T);
which previously e.g. with -std=gnu++14 emitted q = false, but
now emits q = true.

	Jakub

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

* Re: C++ PATCH for testsuite failures with -std=c++17
  2017-05-25  9:08 ` Jakub Jelinek
@ 2017-05-25  9:23   ` Jakub Jelinek
  2017-05-25 21:57     ` Jason Merrill
  0 siblings, 1 reply; 4+ messages in thread
From: Jakub Jelinek @ 2017-05-25  9:23 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches List

On Thu, May 25, 2017 at 10:51:56AM +0200, Jakub Jelinek wrote:
> On Tue, May 09, 2017 at 04:37:16PM -0400, Jason Merrill wrote:
> > For C++17 aggregate bases, we have started adding base fields for
> > empty bases.  The code for calculating whether a class is standard
> > layout needs to ignore these.
> > 
> > The C++17 mode diagnostic for direct-enum-init1.C was incorrect.
> > 
> > Tested x86_64-pc-linux-gnu, applying to trunk.
> 
> > commit 9a612cc30d4b3ef905ce45304545d8b99a3cf5b9
> > Author: Jason Merrill <jason@redhat.com>
> > Date:   Tue May 9 14:15:38 2017 -0400
> > 
> >             * class.c (check_bases): Ignore empty bases.
> 
> This should have referenced PR c++/80605 (and is also a 7 regression).
> 
> > diff --git a/gcc/cp/class.c b/gcc/cp/class.c
> > index fc71766..085dbc3 100644
> > --- a/gcc/cp/class.c
> > +++ b/gcc/cp/class.c
> > @@ -1860,7 +1860,9 @@ check_bases (tree t,
> >  	       members */
> >  	    for (basefield = TYPE_FIELDS (basetype); basefield;
> >  		 basefield = DECL_CHAIN (basefield))
> > -	      if (TREE_CODE (basefield) == FIELD_DECL)
> > +	      if (TREE_CODE (basefield) == FIELD_DECL
> > +		  && DECL_SIZE (basefield)
> > +		  && !integer_zerop (DECL_SIZE (basefield)))
> 
> Is that what we really want?  I mean, shouldn't we at least also
> check that the basefield we want to ignore is DECL_ARTIFICIAL,
> or that it doesn't have DECL_NAME or something similar, to avoid
> considering user fields with zero size the same?
> I believe your change changes e.g.:
> struct S { int a[0]; };
> struct T : public S { int b[0]; int c; };
> bool q = __is_standard_layout (T);
> which previously e.g. with -std=gnu++14 emitted q = false, but
> now emits q = true.

We even have DECL_FIELD_IS_BASE macro, so can't the above be
  if (TREE_CODE (basefield) == FIELD_DECL
      && !DECL_FIELD_IS_BASE (basefield))
or
  if (TREE_CODE (basefield) == FIELD_DECL
      && (!DECL_FIELD_IS_BASE (basefield)
	  || (DECL_SIZE (basefield)
	      && !integer_zerop (DECL_SIZE (basefield)))))
or something similar?

	Jakub

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

* Re: C++ PATCH for testsuite failures with -std=c++17
  2017-05-25  9:23   ` Jakub Jelinek
@ 2017-05-25 21:57     ` Jason Merrill
  0 siblings, 0 replies; 4+ messages in thread
From: Jason Merrill @ 2017-05-25 21:57 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches List

[-- Attachment #1: Type: text/plain, Size: 2235 bytes --]

On Thu, May 25, 2017 at 5:08 AM, Jakub Jelinek <jakub@redhat.com> wrote:
> On Thu, May 25, 2017 at 10:51:56AM +0200, Jakub Jelinek wrote:
>> On Tue, May 09, 2017 at 04:37:16PM -0400, Jason Merrill wrote:
>> > For C++17 aggregate bases, we have started adding base fields for
>> > empty bases.  The code for calculating whether a class is standard
>> > layout needs to ignore these.
>> >
>> > The C++17 mode diagnostic for direct-enum-init1.C was incorrect.
>> >
>> > Tested x86_64-pc-linux-gnu, applying to trunk.
>>
>> > commit 9a612cc30d4b3ef905ce45304545d8b99a3cf5b9
>> > Author: Jason Merrill <jason@redhat.com>
>> > Date:   Tue May 9 14:15:38 2017 -0400
>> >
>> >             * class.c (check_bases): Ignore empty bases.
>>
>> This should have referenced PR c++/80605 (and is also a 7 regression).
>>
>> > diff --git a/gcc/cp/class.c b/gcc/cp/class.c
>> > index fc71766..085dbc3 100644
>> > --- a/gcc/cp/class.c
>> > +++ b/gcc/cp/class.c
>> > @@ -1860,7 +1860,9 @@ check_bases (tree t,
>> >            members */
>> >         for (basefield = TYPE_FIELDS (basetype); basefield;
>> >              basefield = DECL_CHAIN (basefield))
>> > -         if (TREE_CODE (basefield) == FIELD_DECL)
>> > +         if (TREE_CODE (basefield) == FIELD_DECL
>> > +             && DECL_SIZE (basefield)
>> > +             && !integer_zerop (DECL_SIZE (basefield)))
>>
>> Is that what we really want?  I mean, shouldn't we at least also
>> check that the basefield we want to ignore is DECL_ARTIFICIAL,
>> or that it doesn't have DECL_NAME or something similar, to avoid
>> considering user fields with zero size the same?
>> I believe your change changes e.g.:
>> struct S { int a[0]; };
>> struct T : public S { int b[0]; int c; };
>> bool q = __is_standard_layout (T);
>> which previously e.g. with -std=gnu++14 emitted q = false, but
>> now emits q = true.
>
> We even have DECL_FIELD_IS_BASE macro, so can't the above be
>   if (TREE_CODE (basefield) == FIELD_DECL
>       && !DECL_FIELD_IS_BASE (basefield))
> or
>   if (TREE_CODE (basefield) == FIELD_DECL
>       && (!DECL_FIELD_IS_BASE (basefield)
>           || (DECL_SIZE (basefield)
>               && !integer_zerop (DECL_SIZE (basefield)))))
> or something similar?

Indeed, thanks.

[-- Attachment #2: 80605.diff --]
[-- Type: text/plain, Size: 1205 bytes --]

commit 49096cb5bc6c629c619ac9b5e08b971867dd1fc1
Author: Jason Merrill <jason@redhat.com>
Date:   Thu May 25 15:34:13 2017 -0400

            PR c++/80605 - __is_standard_layout and zero-length array
    
            * class.c (check_bases): Use DECL_FIELD_IS_BASE.

diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index 984fb09..eddc118 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -1842,8 +1842,8 @@ check_bases (tree t,
 	    for (basefield = TYPE_FIELDS (basetype); basefield;
 		 basefield = DECL_CHAIN (basefield))
 	      if (TREE_CODE (basefield) == FIELD_DECL
-		  && DECL_SIZE (basefield)
-		  && !integer_zerop (DECL_SIZE (basefield)))
+		  && !(DECL_FIELD_IS_BASE (basefield)
+		       && integer_zerop (DECL_SIZE (basefield))))
 		{
 		  if (field)
 		    CLASSTYPE_NON_STD_LAYOUT (t) = 1;
diff --git a/gcc/testsuite/g++.dg/ext/is_std_layout2.C b/gcc/testsuite/g++.dg/ext/is_std_layout2.C
new file mode 100644
index 0000000..02dc4f7
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/is_std_layout2.C
@@ -0,0 +1,6 @@
+// { dg-do compile { target c++11 } }
+// { dg-options "" }
+
+struct S { int a[0]; };
+struct T : public S { int b[0]; int c; };
+static_assert(!__is_standard_layout (T), "");

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

end of thread, other threads:[~2017-05-25 21:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-09 20:42 C++ PATCH for testsuite failures with -std=c++17 Jason Merrill
2017-05-25  9:08 ` Jakub Jelinek
2017-05-25  9:23   ` Jakub Jelinek
2017-05-25 21:57     ` 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).