https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87934

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org,
                   |                            |jason at gcc dot gnu.org

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
cxx_eval_constant_expression doesn't fold this, because {.bar=BAR} CONSTRUCTOR
is TREE_CONSTANT, but not reduced_constant_expression_p, as it contains the
CONST_DECL in it and we have:
4684          if (TREE_CONSTANT (t))
4685            {
4686              /* Don't re-process a constant CONSTRUCTOR, but do fold it to
4687                 VECTOR_CST if applicable.  */
4688              verify_constructor_flags (t);
4689              if (TREE_CONSTANT (t))
4690                return fold (t);
4691            }
4692          r = cxx_eval_bare_aggregate (ctx, t, lval,
4693                                       non_constant_p, overflow_p);
So, to fix this, we either need to make sure that the CONSTRUCTOR is cp_folded
when it is being created, or to check above reduced_constant_expression_p
instead of in addition to TREE_CONSTANT, or change fold in fold-const.c, so
that if it sees CONST_DECLs in there, they are folded too.  But it would need
to do it recursively.

To me changing cxx_eval_const_expression looks easiest, but dunno if it is
correct thing to do.

Reply via email to