[cfe-dev] [RFC] Control -Wvla for conformant parameters

Aaron Ballman via cfe-dev cfe-dev at lists.llvm.org
Mon Nov 8 09:37:36 PST 2021


On Mon, Nov 8, 2021 at 12:18 PM Arthur O'Dwyer
<arthur.j.odwyer at gmail.com> wrote:
>
> On Mon, Nov 8, 2021 at 12:04 PM Aaron Ballman <aaron at aaronballman.com> wrote:
>>
>> On Mon, Nov 8, 2021 at 11:11 AM Arthur O'Dwyer <arthur.j.odwyer at gmail.com> wrote:
>> >
>> > IIUC, Clang currently misdiagnoses
>> > https://godbolt.org/z/6x7399eqP
>> >     return sizeof(int (*)(int[n]));  // -Wvla warns here (wrongly)
>> > because `int (*)(int[n])` is not a variably modified type — is that right? So it would be cool to clean up some of this code at the same time.
>>
>> I'd have to stare at the C standard a while to be sure, but I think
>> that is a variably modified type, but is not a VLA. Regardless, I
>> agree that there's likely terminology that needs to be cleaned up as
>> part of this.
>
>
> IIUC, `int (*)(int[n])` is the same type as `int (*)(int*)` — and yes, I should have thought to spell that out clearly in my first message. :)

You nerd sniped me into checking. :-D It's a VLA... which decays into
a pointer... so everyone is correct.

C2x (N2596) 6.7.6.2p4 specifies that the type of the parameter is a
variable length array type.
C2x (N2596) 6.7.6.3p6 is what does the array adjustments that convert
it from an array to a pointer.

I should note, GCC also diagnoses that as a VLA.

~Aaron

>
> –Arthur


More information about the cfe-dev mailing list