[Bug c/106535] GCC doesn't reject non-constant initializer if -pedantic is specified but does so in any other circumstances

2022-08-05 Thread gabravier at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106535

--- Comment #3 from Gabriel Ravier  ---
Considering the comment appears to be from 1993 (see commit
d9fc6069c69564ce7fecd9ca0ce1bbe0b3c130ef), it having become wrong since then
doesn't seem particularly surprising :p

[Bug c/106535] GCC doesn't reject non-constant initializer if -pedantic is specified but does so in any other circumstances

2022-08-05 Thread redi at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106535

Jonathan Wakely  changed:

   What|Removed |Added

   Keywords||diagnostic
 Status|UNCONFIRMED |NEW
 Ever confirmed|0   |1
   Last reconfirmed||2022-08-05

--- Comment #2 from Jonathan Wakely  ---
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.

[Bug c/106535] GCC doesn't reject non-constant initializer if -pedantic is specified but does so in any other circumstances

2022-08-05 Thread gabravier at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106535

Gabriel Ravier  changed:

   What|Removed |Added

   Keywords||accepts-invalid,
   ||rejects-valid

--- Comment #1 from Gabriel Ravier  ---
(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)