public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ PATCH] Allow value initialization of classes with flexible array member (PR c++/87148)
@ 2019-03-05 22:29 Jakub Jelinek
  2019-03-06 15:08 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2019-03-05 22:29 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches

Hi!

In this PR, Jonathan argues that we should accept value initialization of
classes with flexible array member.

The following patch does that.  Bootstrapped/regtested on x86_64-linux
and i686-linux, ok for trunk?

2019-03-05  Jakub Jelinek  <jakub@redhat.com>

	PR c++/87148
	* init.c (build_value_init_noctor): Ignore flexible array members.

	* g++.dg/ext/flexary34.C: New test.

--- gcc/cp/init.c.jj	2019-03-05 15:34:17.164490227 +0100
+++ gcc/cp/init.c	2019-03-05 15:34:27.140327205 +0100
@@ -419,6 +419,15 @@ build_value_init_noctor (tree type, tsub
 	      if (ftype == error_mark_node)
 		continue;
 
+	      /* Ignore flexible array members for value initialization.  */
+	      if (TREE_CODE (ftype) == ARRAY_TYPE
+		  && !COMPLETE_TYPE_P (ftype)
+		  && !TYPE_DOMAIN (ftype)
+		  && COMPLETE_TYPE_P (TREE_TYPE (ftype))
+		  && (next_initializable_field (DECL_CHAIN (field))
+		      == NULL_TREE))
+		continue;
+
 	      /* We could skip vfields and fields of types with
 		 user-defined constructors, but I think that won't improve
 		 performance at all; it should be simpler in general just
--- gcc/testsuite/g++.dg/ext/flexary34.C.jj	2019-03-05 15:31:38.731079324 +0100
+++ gcc/testsuite/g++.dg/ext/flexary34.C	2019-03-05 15:32:46.852966084 +0100
@@ -0,0 +1,10 @@
+// PR c++/87148
+// { dg-do compile }
+// { dg-options "-pedantic" }
+
+struct Tst { int i; char t[]; };	// { dg-warning "forbids flexible array member" }
+
+Tst t {};				// { dg-warning "extended initializer lists only available with" "" { target c++98_only } }
+Tst u = Tst();
+void foo () { Tst u = {}; }
+Tst *bar () { return new Tst (); }

	Jakub

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

* Re: [C++ PATCH] Allow value initialization of classes with flexible array member (PR c++/87148)
  2019-03-05 22:29 [C++ PATCH] Allow value initialization of classes with flexible array member (PR c++/87148) Jakub Jelinek
@ 2019-03-06 15:08 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2019-03-06 15:08 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

On 3/5/19 5:23 PM, Jakub Jelinek wrote:
> Hi!
> 
> In this PR, Jonathan argues that we should accept value initialization of
> classes with flexible array member.
> 
> The following patch does that.  Bootstrapped/regtested on x86_64-linux
> and i686-linux, ok for trunk?

OK.

Jason

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

end of thread, other threads:[~2019-03-06 15:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-05 22:29 [C++ PATCH] Allow value initialization of classes with flexible array member (PR c++/87148) Jakub Jelinek
2019-03-06 15:08 ` 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).