Skip to content

Clang and gcc disagree on whether a const struct is a compile-time constant #44502

Closed
llvm/llvm-project-release-prs
#517
@nickdesaulniers

Description

@nickdesaulniers
Bugzilla Link 45157
Version trunk
OS All
Blocks #4440
CC @DougGregor,@efriedma-quic,@isanbard,@jyknight,@lalozano,@zygoloid,@stephenhines

Extended Description

struct foo {};
struct bar{
    struct foo foo;
};

static const struct foo my_foo = {};
static const struct bar my_bar = {
    .foo = my_foo,
};

Clang produces:

<source>:8:12: error: initializer element is not a compile-time constant

    .foo = my_foo,

           ^~~~~~

GCC has no error.

A recent CI run on the Linux kernel failed for Clang on this patch:
https://cgit.freedesktop.org/~jani/drm/commit/?h=device-info-inheritance-v3&id=329fec687c7310f3a68ae1c6fd3638274484f149

Metadata

Metadata

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions