On 07/22/2016 01:14 PM, Martin Sebor wrote: > r231665 committed in the 6.0 cycle tightened up the checking of > flexible array members in C++ with the goal of rejecting code > that could lead to hard to find bugs, while at the same time > accepting (with a warning) benign extensions also accepted in > C mode. > > c++/71912 is a complaint that G++ rejects one such extension: > defining structs with flexible array members in a union. When > reviewing the code that causes it to be rejected I realized > that it was, in fact, meant to be accepted and is rejected due > to a bug. > > The attached patch fixes that bug and implements more robust > checking for this class of problems. As in C mode, it accepts > "benign" instances of this idiom (with a pedantic warning) while > still rejecting the erroneous cases. > > There are outstanding problems with flexible array members in > C++, such as c++/68489 - arrays of flexible array members are > silently accepted. In a follow-on patch I will address at > least a part of the problem. I submit this one separately > since it's considered a regression and as such might be > a candidate for backporting to the 6.x branch. > > Is this patch okay for trunk? For 6.x? I had looked at the wrong set of test results before posting the first patch and missed a bunch of test suite failures due to a bug that let the find_flexarray function descend into static data members when looking for flexible array members, causing infinite recursion. The attached patch fixes that, adds a new test to exercise the previously untested static data members, and annotates an invalid regression test with a gd-error directive. Martin