]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/11614 (Incorrect handling of pointers to arrays)
authorNathan Sidwell <nathan@codesourcery.com>
Tue, 22 Jul 2003 16:49:48 +0000 (16:49 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Tue, 22 Jul 2003 16:49:48 +0000 (16:49 +0000)
cp:
PR c++/11614
* decl.c (grokdeclarator): An array member is only a flexible
array member if the field itself is the array.
testsuite:
* g++.dg/ext/flexary1.C: New test.

From-SVN: r69673

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/ext/flexary1.C [new file with mode: 0644]

index 79565c65bec8327890f81dd10589371818b4afb8..8f37c7e872340d96229916a945815c4032be8c28 100644 (file)
@@ -1,3 +1,9 @@
+2003-07-22  Nathan Sidwell  <nathan@codesourcery.com>
+
+       PR c++/11614
+       * decl.c (grokdeclarator): An array member is only a flexible
+       array member if the field itself is the array.
+
 2003-07-22  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>
 
        PR c++/10793
index 9e90d9e904549bbbbfd10b23aa6a1c595f71ed34..22137be5967924bd7c2036d5ddde75d90d7d1faf 100644 (file)
@@ -10615,14 +10615,18 @@ grokdeclarator (tree declarator,
            register tree size;
 
            size = TREE_OPERAND (declarator, 1);
+           declarator = TREE_OPERAND (declarator, 0);
 
-           /* VC++ spells a zero-sized array with [].  */
+           /* C99 spells a flexible array member [].  */
            if (size == NULL_TREE && decl_context == FIELD && ! staticp
-               && ! RIDBIT_SETP (RID_TYPEDEF, specbits))
+               && ! RIDBIT_SETP (RID_TYPEDEF, specbits)
+               && !(declarator &&
+                   (TREE_CODE (declarator) == CALL_EXPR
+                     || TREE_CODE (declarator) == INDIRECT_REF
+                     || TREE_CODE (declarator) == ADDR_EXPR
+                     || TREE_CODE (declarator) == ARRAY_REF)))
              size = integer_zero_node;
 
-           declarator = TREE_OPERAND (declarator, 0);
-
            type = create_array_type_for_decl (dname, type, size);
 
            ctype = NULL_TREE;
index eddfa73d3b49cfe026d6686cd14a903f975ba9d7..085f25d4ec54a5c4401665b505e623ce84c5150b 100644 (file)
@@ -1,3 +1,7 @@
+2003-07-22  Nathan Sidwell  <nathan@codesourcery.com>
+
+       * g++.dg/ext/flexary1.C: New test.
+       
 2003-07-22  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>
 
        PR c++/10793
diff --git a/gcc/testsuite/g++.dg/ext/flexary1.C b/gcc/testsuite/g++.dg/ext/flexary1.C
new file mode 100644 (file)
index 0000000..4033e33
--- /dev/null
@@ -0,0 +1,33 @@
+// { dg-do compile }
+
+// Copyright (C) 2003 Free Software Foundation, Inc.
+// Contributed by Nathan Sidwell 22 Jul 2003 <nathan@codesourcery.com>
+
+// PR c++ 11614
+
+typedef int ary_t[];
+
+struct test
+{
+  ary_t *b;
+  int (*a)[]; // this is not a flexible array member
+};
+void test(void)
+{
+  struct test s;
+  int (*a)[] = 0;
+  ary_t *b = 0;
+  
+  a = s.a;
+  a = s.b;
+
+  s.a = a;
+  s.b = a;
+
+  b = s.a;
+  b = s.b;
+
+  s.a = b;
+  s.b = b;
+}