public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C PATCH] Another initialization fix (PR c/63567)
@ 2014-10-19 15:49 Marek Polacek
  2014-10-19 16:37 ` Joseph S. Myers
  0 siblings, 1 reply; 2+ messages in thread
From: Marek Polacek @ 2014-10-19 15:49 UTC (permalink / raw)
  To: GCC Patches, Joseph S. Myers

It turned out that there is another spot where we need to allow
initializing objects with static storage duration with compound
literals even in C99 -- when the compound literal is inside the
initializer.  Fixed in the same way as previously.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2014-10-18  Marek Polacek  <polacek@redhat.com>

	PR c/63567
	* c-typeck.c (output_init_element): Allow initializing objects with
	static storage duration with compound literals even in C99 and add
	pedwarn for it.

	* gcc.dg/pr63567-3.c: New test.
	* gcc.dg/pr63567-4.c: New test.

diff --git gcc/c/c-typeck.c gcc/c/c-typeck.c
index 0dd3366..ee874da 100644
--- gcc/c/c-typeck.c
+++ gcc/c/c-typeck.c
@@ -8251,11 +8251,14 @@ output_init_element (location_t loc, tree value, tree origtype,
     value = array_to_pointer_conversion (input_location, value);
 
   if (TREE_CODE (value) == COMPOUND_LITERAL_EXPR
-      && require_constant_value && !flag_isoc99 && pending)
+      && require_constant_value && pending)
     {
       /* As an extension, allow initializing objects with static storage
 	 duration with compound literals (which are then treated just as
 	 the brace enclosed list they contain).  */
+      if (flag_isoc99)
+	pedwarn_init (loc, OPT_Wpedantic, "initializer element is not "
+		      "constant");
       tree decl = COMPOUND_LITERAL_EXPR_DECL (value);
       value = DECL_INITIAL (decl);
     }
diff --git gcc/testsuite/gcc.dg/pr63567-3.c gcc/testsuite/gcc.dg/pr63567-3.c
index e69de29..d626406 100644
--- gcc/testsuite/gcc.dg/pr63567-3.c
+++ gcc/testsuite/gcc.dg/pr63567-3.c
@@ -0,0 +1,7 @@
+/* PR c/63567 */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+struct T { int i; };
+struct S { struct T t; };
+struct S s = { .t = { (int) { 1 } } };
diff --git gcc/testsuite/gcc.dg/pr63567-4.c gcc/testsuite/gcc.dg/pr63567-4.c
index e69de29..0ca6c45 100644
--- gcc/testsuite/gcc.dg/pr63567-4.c
+++ gcc/testsuite/gcc.dg/pr63567-4.c
@@ -0,0 +1,7 @@
+/* PR c/63567 */
+/* { dg-do compile } */
+/* { dg-options "-Wpedantic" } */
+
+struct T { int i; };
+struct S { struct T t; };
+struct S s = { .t = { (int) { 1 } } }; /* { dg-warning "initializer element is not constant" } */

	Marek

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

* Re: [C PATCH] Another initialization fix (PR c/63567)
  2014-10-19 15:49 [C PATCH] Another initialization fix (PR c/63567) Marek Polacek
@ 2014-10-19 16:37 ` Joseph S. Myers
  0 siblings, 0 replies; 2+ messages in thread
From: Joseph S. Myers @ 2014-10-19 16:37 UTC (permalink / raw)
  To: Marek Polacek; +Cc: GCC Patches

On Sun, 19 Oct 2014, Marek Polacek wrote:

> It turned out that there is another spot where we need to allow
> initializing objects with static storage duration with compound
> literals even in C99 -- when the compound literal is inside the
> initializer.  Fixed in the same way as previously.
> 
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
> 
> 2014-10-18  Marek Polacek  <polacek@redhat.com>
> 
> 	PR c/63567
> 	* c-typeck.c (output_init_element): Allow initializing objects with
> 	static storage duration with compound literals even in C99 and add
> 	pedwarn for it.
> 
> 	* gcc.dg/pr63567-3.c: New test.
> 	* gcc.dg/pr63567-4.c: New test.

OK.

-- 
Joseph S. Myers
joseph@codesourcery.com

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

end of thread, other threads:[~2014-10-19 16:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-19 15:49 [C PATCH] Another initialization fix (PR c/63567) Marek Polacek
2014-10-19 16:37 ` Joseph S. Myers

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).