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

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

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

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(struct Test2){3, 4}
is a compound literal, see
https://en.cppreference.com/w/c/language/compound_literal
for further details, so it isn't a valid constant expression, it is like
doing
struct Test2
{
    long int x;
    long int y;
};

struct Test
{
    long int x;
    struct Test2 t;
};

struct Test2 tmp2={3, 4};
struct Test tmp1={1, tmp2};
struct Test t=tmp1;
except that the compound literals introduce unnamed, not named objects.
The above is also rejected, by both GCC and Clang.
Note, implementations may accept as constant expressions even expressions the
standard doesn't require to be constant expressions, so probably that is the
reason why Clang chooses to accept it.  Though, at least without using const
struct Test{,2} in the compound literals it is actually an unnamed object that
can be modified, so it is weird it is accepted.
The above testcase with tmp2/tmp1 is as an extension accepted by GCC when one
uses const struct Test2 or const struct Test (but rejected by Clang), though
if you use it in the compound literals, we don't accept that.

Reply via email to