public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/106535] New: GCC doesn't reject non-constant initializer if -pedantic is specified but does so in any other circumstances
@ 2022-08-05 9:57 gabravier at gmail dot com
2022-08-05 9:58 ` [Bug c/106535] " gabravier at gmail dot com
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: gabravier at gmail dot com @ 2022-08-05 9:57 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106535
Bug ID: 106535
Summary: GCC doesn't reject non-constant initializer if
-pedantic is specified but does so in any other
circumstances
Product: gcc
Version: 13.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: gabravier at gmail dot com
Target Milestone: ---
int f = (0, 0);
Compiled without any options:
<source>:1:9: error: initializer element is not constant
1 | int f = (0, 0);
| ^
Compiled with -pedantic:
<source>:1:9: warning: initializer element is not constant [-Wpedantic]
1 | int f = (0, 0);
| ^
It seems rather odd that adding -pedantic transforms an error into a warning...
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c/106535] GCC doesn't reject non-constant initializer if -pedantic is specified but does so in any other circumstances
2022-08-05 9:57 [Bug c/106535] New: GCC doesn't reject non-constant initializer if -pedantic is specified but does so in any other circumstances gabravier at gmail dot com
@ 2022-08-05 9:58 ` gabravier at gmail dot com
2022-08-05 10:17 ` redi at gcc dot gnu.org
2022-08-05 14:04 ` gabravier at gmail dot com
2 siblings, 0 replies; 4+ messages in thread
From: gabravier at gmail dot com @ 2022-08-05 9:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106535
Gabriel Ravier <gabravier at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |accepts-invalid,
| |rejects-valid
--- Comment #1 from Gabriel Ravier <gabravier at gmail dot com> ---
(PS: I'm not sure whether it's intended that it should be rejected under
-pedantic or accepted without any options, so I've used both of the keywords)
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c/106535] GCC doesn't reject non-constant initializer if -pedantic is specified but does so in any other circumstances
2022-08-05 9:57 [Bug c/106535] New: GCC doesn't reject non-constant initializer if -pedantic is specified but does so in any other circumstances gabravier at gmail dot com
2022-08-05 9:58 ` [Bug c/106535] " gabravier at gmail dot com
@ 2022-08-05 10:17 ` redi at gcc dot gnu.org
2022-08-05 14:04 ` gabravier at gmail dot com
2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2022-08-05 10:17 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106535
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |diagnostic
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
Last reconfirmed| |2022-08-05
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Looks like this comment is not correct:
/* Compound expressions can only occur here if -Wpedantic or
-pedantic-errors is specified. In the later case, we always want
an error. In the former case, we simply want a warning. */
if (require_constant && pedantic
&& TREE_CODE (inside_init) == COMPOUND_EXPR)
{
inside_init
= valid_compound_expr_initializer (inside_init,
TREE_TYPE (inside_init));
if (inside_init == error_mark_node)
error_init (init_loc, "initializer element is not constant");
else
pedwarn_init (init_loc, OPT_Wpedantic,
"initializer element is not constant");
if (flag_pedantic_errors)
inside_init = error_mark_node;
}
else if (require_constant
&& !initializer_constant_valid_p (inside_init,
TREE_TYPE (inside_init)))
{
error_init (init_loc, "initializer element is not constant");
inside_init = error_mark_node;
}
else if (require_constant && !maybe_const)
pedwarn_init (init_loc, OPT_Wpedantic,
"initializer element is not a constant expression");
Without -pedantic the first condition is false, so it takes the second branch
which uses error_init. With -pedantic the first branch is taken, and it uses
pedwarn_init which is only a warning unless you use -pedantic-errors.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c/106535] GCC doesn't reject non-constant initializer if -pedantic is specified but does so in any other circumstances
2022-08-05 9:57 [Bug c/106535] New: GCC doesn't reject non-constant initializer if -pedantic is specified but does so in any other circumstances gabravier at gmail dot com
2022-08-05 9:58 ` [Bug c/106535] " gabravier at gmail dot com
2022-08-05 10:17 ` redi at gcc dot gnu.org
@ 2022-08-05 14:04 ` gabravier at gmail dot com
2 siblings, 0 replies; 4+ messages in thread
From: gabravier at gmail dot com @ 2022-08-05 14:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106535
--- Comment #3 from Gabriel Ravier <gabravier at gmail dot com> ---
Considering the comment appears to be from 1993 (see commit
d9fc6069c69564ce7fecd9ca0ce1bbe0b3c130ef), it having become wrong since then
doesn't seem particularly surprising :p
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-08-05 14:04 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-05 9:57 [Bug c/106535] New: GCC doesn't reject non-constant initializer if -pedantic is specified but does so in any other circumstances gabravier at gmail dot com
2022-08-05 9:58 ` [Bug c/106535] " gabravier at gmail dot com
2022-08-05 10:17 ` redi at gcc dot gnu.org
2022-08-05 14:04 ` gabravier at gmail dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).