[Bug c/71713] "initializer element is not constant" with nested casts
msebor at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Fri Jul 1 22:40:00 GMT 2016
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71713
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2016-07-01
CC| |msebor at gcc dot gnu.org
Ever confirmed|0 |1
Severity|minor |enhancement
--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
I believe the error is justified because a compound literal (i.e., "(struct
Str1){1}") is not a constant expression, and so it cannot be used to initialize
an object with static storage duration. GCC accepts compound literals as
initializers in some contexts as an extension but not here. For instance, the
following is accepted but in pedantic mode diagnosed with
struct Str1 x = (struct Str1){ 0 };
warning: initializer element is not constant [-Wpedantic]
...but it doesn't accept the more involved initializer in the submitted test
case. Since there are a number of enhancement requests to change GCC to accept
more expressions as initializers that aren't constant expressions (for example,
bug 53091) I will confirm this as such.
More information about the Gcc-bugs
mailing list