[Bug c++/71912] [6/7 regression] flexible array in struct in union rejected

2016-10-13 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71912

--- Comment #7 from Martin Sebor  ---
Author: msebor
Date: Thu Oct 13 22:26:36 2016
New Revision: 241143

URL: https://gcc.gnu.org/viewcvs?rev=241143=gcc=rev
Log:
PR c++/71912 - [6/7 regression] flexible array in struct in union rejected

gcc/cp/ChangeLog:

PR c++/71912
* class.c (struct flexmems_t):  Add members.
(find_flexarrays): Add arguments.  Correct handling of anonymous
structs.
(diagnose_flexarrays): Adjust to issue warnings in addition to errors.
(check_flexarrays): Add argument.
(diagnose_invalid_flexarray): New functions.

gcc/testsuite/ChangeLog:

PR c++/71912
* g++.dg/ext/flexary4.C: Adjust.
* g++.dg/ext/flexary5.C: Same.
* g++.dg/ext/flexary9.C: Same.
* g++.dg/ext/flexary19.C: New test.
* g++.dg/ext/flexary18.C: New test.
* g++.dg/torture/pr64312.C: Add a dg-error directive to an ill-formed
regression test.
* g++.dg/compat/struct-layout-1_generate.c (subfield): Add argument.
Avoid generating a flexible array member in an array.


Added:
trunk/gcc/testsuite/g++.dg/ext/flexary18.C
trunk/gcc/testsuite/g++.dg/ext/flexary19.C
Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/class.c
trunk/gcc/testsuite/ChangeLog
trunk/gcc/testsuite/g++.dg/compat/struct-layout-1_generate.c
trunk/gcc/testsuite/g++.dg/ext/flexary4.C
trunk/gcc/testsuite/g++.dg/ext/flexary5.C
trunk/gcc/testsuite/g++.dg/ext/flexary9.C
trunk/gcc/testsuite/g++.dg/torture/pr64312.C

[Bug c++/71912] [6/7 regression] flexible array in struct in union rejected

2016-09-11 Thread pinskia at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71912

Andrew Pinski  changed:

   What|Removed |Added

   Target Milestone|--- |6.3

[Bug c++/71912] [6/7 regression] flexible array in struct in union rejected

2016-07-22 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71912

--- Comment #6 from Martin Sebor  ---
Patch posted for review:
  https://gcc.gnu.org/ml/gcc-patches/2016-07/msg01505.html

[Bug c++/71912] [6/7 regression] flexible array in struct in union rejected

2016-07-19 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71912

Martin Sebor  changed:

   What|Removed |Added

 Blocks||69698
   Severity|normal  |minor

--- Comment #5 from Martin Sebor  ---
(In reply to Martin Sebor from comment #4)
> Even though GCC with -Wpedantic silently accepts the equivalent definition
> of struct xyyzy, it issues a diagnostic for baz supporting the
> interpretation above:
> 
>   warning: invalid use of structure with flexible array member
> 
> Since the struct definitions are equivalent, it seems that either they both
> should be diagnosed or neither should be.

Let me correct the above.  GCC does give a pedantic warning in both cases
confirming that the test case is, strictly speaking, invalid.  (I must have
missed it somehow.)  Clang too diagnoses it with -Wflexible-array-extensions:

  warning: 'u' may not be nested in a struct due to flexible array

I'm lowering the Severity to Minor but I will fix the C++ error for
compatibility with GCC.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69698
[Bug 69698] [meta-bug] flexible array members

[Bug c++/71912] [6/7 regression] flexible array in struct in union rejected

2016-07-18 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71912

Martin Sebor  changed:

   What|Removed |Added

 Status|UNCONFIRMED |ASSIGNED
   Last reconfirmed||2016-07-18
  Known to work||5.4.0
   Assignee|unassigned at gcc dot gnu.org  |msebor at gcc dot 
gnu.org
Summary|flexible array in union |[6/7 regression] flexible
   ||array in struct in union
   ||rejected
 Ever confirmed|0   |1
  Known to fail||6.1.0, 7.0

--- Comment #4 from Martin Sebor  ---
I confirm the code in the test case is meant to be accepted by G++ for
compatibility with GCC but is rejected due to a bug in the find_flexarrays
function in class.c.

That said, it's not completely clear that the code is valid according to the C
definition of a flexible array member:

  As a special case, the last element of a structure with more than one named
member may have an incomplete array type; this is called a /flexible array
member/.

Although C doesn't define the term element, I think it means the last declared
subobject of an object.

In the test case, neither of the two flexible array members is the last element
of struct xyyzy (the last element is the subobject u).  Within the member u of
struct xyyzy, the flexible array member f.s is not the last element of the
structure xyyzy (b.t is the last element).

Even though GCC with -Wpedantic silently accepts the equivalent definition of
struct xyyzy, it issues a diagnostic for baz supporting the interpretation
above:

  warning: invalid use of structure with flexible array member

Since the struct definitions are equivalent, it seems that either they both
should be diagnosed or neither should be.