c-parse.in (cast_expr): Move compound literals from here ...
authorJoseph Myers <jsm28@cam.ac.uk>
Wed, 24 Jan 2001 20:41:49 +0000 (20:41 +0000)
committerJoseph Myers <jsm28@gcc.gnu.org>
Wed, 24 Jan 2001 20:41:49 +0000 (20:41 +0000)
* c-parse.in (cast_expr): Move compound literals from here ...
(primary): ... to here.  Use standard terminology "compound
literal" instead of "constructor expression".

testsuite:
* gcc.c-torture/compile/20010124-1.c: New test.

From-SVN: r39246

gcc/ChangeLog
gcc/c-parse.in
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/compile/20010124-1.c [new file with mode: 0644]

index a09869a8aee3ef5c7d7c6956245ae67e13f16541..9f8b613c7731fa7cbb8e7896fb970c57abb115c3 100644 (file)
@@ -1,3 +1,9 @@
+2001-01-24  Joseph S. Myers  <jsm28@cam.ac.uk>
+
+       * c-parse.in (cast_expr): Move compound literals from here ...
+       (primary): ... to here.  Use standard terminology "compound
+       literal" instead of "constructor expression".
+
 2001-01-24  Joseph S. Myers  <jsm28@cam.ac.uk>
 
        * gcc.1, cpp.1: Regenerate.
index 30f2551b26f8ee4779ec18697e602d24cb741692..5b32768866c70c5bd917405ba0face7ddfa4788a 100644 (file)
@@ -542,35 +542,6 @@ cast_expr:
                  type = groktypename ($2);
                  warn_strict_prototypes = SAVED_warn_strict_prototypes;
                  $$ = build_c_cast (type, $4); }
-       | '(' typename ')' '{' 
-               { start_init (NULL_TREE, NULL, 0);
-                 $2 = groktypename ($2);
-                 really_start_incremental_init ($2); }
-         initlist_maybe_comma '}'  %prec UNARY
-               { const char *name;
-                 tree result = pop_init_level (0);
-                 tree type = $2;
-                 finish_init ();
-
-                 if (pedantic && ! flag_isoc99)
-                   pedwarn ("ISO C89 forbids constructor expressions");
-                 if (TYPE_NAME (type) != 0)
-                   {
-                     if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
-                       name = IDENTIFIER_POINTER (TYPE_NAME (type));
-                     else
-                       name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
-                   }
-                 else
-                   name = "";
-                 $$ = result;
-                 if (TREE_CODE (type) == ARRAY_TYPE && !COMPLETE_TYPE_P (type))
-                   {
-                     int failure = complete_array_type (type, $$, 1);
-                     if (failure)
-                       abort ();
-                   }
-               }
        ;
 
 expr_no_commas:
@@ -659,6 +630,35 @@ primary:
        | CONSTANT
        | string
                { $$ = combine_strings ($1); }
+       | '(' typename ')' '{' 
+               { start_init (NULL_TREE, NULL, 0);
+                 $2 = groktypename ($2);
+                 really_start_incremental_init ($2); }
+         initlist_maybe_comma '}'  %prec UNARY
+               { const char *name;
+                 tree result = pop_init_level (0);
+                 tree type = $2;
+                 finish_init ();
+
+                 if (pedantic && ! flag_isoc99)
+                   pedwarn ("ISO C89 forbids compound literals");
+                 if (TYPE_NAME (type) != 0)
+                   {
+                     if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
+                       name = IDENTIFIER_POINTER (TYPE_NAME (type));
+                     else
+                       name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
+                   }
+                 else
+                   name = "";
+                 $$ = result;
+                 if (TREE_CODE (type) == ARRAY_TYPE && !COMPLETE_TYPE_P (type))
+                   {
+                     int failure = complete_array_type (type, $$, 1);
+                     if (failure)
+                       abort ();
+                   }
+               }
        | '(' expr ')'
                { char class = TREE_CODE_CLASS (TREE_CODE ($2));
                  if (class == 'e' || class == '1'
index 197e6cab89d6e2ad2688f220a0804d0eada29e3e..c68a93d35f02ec313cfce79034ff230352143aeb 100644 (file)
@@ -1,3 +1,7 @@
+2001-01-24  Joseph S. Myers  <jsm28@cam.ac.uk>
+
+       * gcc.c-torture/compile/20010124-1.c: New test.
+
 2001-01-24  Nathan Sidwell  <nathan@codesourcery.com>
 
        * g++.old-deja/g++.pt/spec38.C: New test.
diff --git a/gcc/testsuite/gcc.c-torture/compile/20010124-1.c b/gcc/testsuite/gcc.c-torture/compile/20010124-1.c
new file mode 100644 (file)
index 0000000..dd2d9c1
--- /dev/null
@@ -0,0 +1,9 @@
+/* Origin: testcase from Joseph Myers <jsm28@cam.ac.uk>, problem pointed
+   out in a post to comp.std.c
+   <980283801.3063.0.nnrp-07.c2deb1c2@news.demon.co.uk>
+   by Dibyendu Majumdar <dibyendu@mazumdar.demon.co.uk>.
+   Compound literals should be parsed as postfix expressions, rather than
+   as cast expressions.  In particular, they are valid operands of sizeof.  */
+
+struct s { int a; int b; };
+char x[((sizeof (struct s){ 1, 2 }) == sizeof (struct s)) ? 1 : -1];