Skip to content

file-scoped variably modified type erroneously supported in C as a GNU extension (GCC provides the extension only for C++) #43751

@DesWurstes

Description

@DesWurstes
Bugzilla Link 44406
Resolution FIXED
Resolved on Oct 28, 2021 20:57
Version unspecified
OS All
CC @pascal-cuoq,@dwblaikie,@DougGregor,@efriedma-quic,@nickdesaulniers,@zygoloid
Fixed by commit(s) 552c6c2

Extended Description

const int a = 32;

typedef struct {
char c[a];
} d;

GCC: error: variably modified 'c' at file scope
CompCert: error: size of array is not a compile-time constant

Clang -Wextra: compiles
Clang -pedantic: warning: variable length array folded to constant array as an extension [-Wgnu-folding-constant]

The problem? This is not a GNU extension. Either the warning is wrong or the code that shouldn't compile compiles.

Weirdly, MSVC has the same behavior as Clang but does not issue a warning.

Once it is confirmed, I'll file an Apple bug report, because an Xcode header, Security.framework/Headers/Authorization.h suffers from this issue and can only be compiled with Clang (so when this bug is patched don't tell me that I broke Apple's code :) )

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillac

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions