[PATCH] diagnosing flexible array assignments
Arthur O'Dwyer
arthur.j.odwyer at gmail.com
Tue Sep 10 16:36:49 PDT 2013
On Tue, Sep 10, 2013 at 3:12 PM, Eli Friedman <eli.friedman at gmail.com> wrote:
> On Tue, Sep 10, 2013 at 2:50 PM, Aaron Ballman <aaron at aaronballman.com> wrote:
>> >>
>> >> Hmmm, would there ever be a case where it would make sense to declare
>> >> a structure with a flexible array member as a value type? The only
>> >> situation I could think of would be overlaying the value type with
>> >> stack-allocated memory in some sort of bizarre union type punning
>> >> scenario. So I'm thinking that may be a better approach than checking
>> >> on assignment, unless there are intermediary ways you could get this
>> >> assignment to happen in C.
[...]
>> Assignment would be the catch-all way to do it, since that's
>> what causes the slicing behavior. Perhaps both declaration and
>> assignment diagnostics would make sense? Declarations like that are
>> definitively bizarre, but assignment still misbehaves.
Remember to consider
void foo(struct S s) { ... } ... foo(s); ...
which doesn't contain any assignment-expressions, but still slices the
struct (if I understand correctly). So yeah, you'll want to have
warnings on declarations *and* assignments.
–Arthur
More information about the cfe-commits
mailing list