Skip to content

[clang] initializer element is not a compile-time constant error when trying to initialize static array with elemment of type static const struct #61737

Open
@listout

Description

@listout

I came across this while building gnome-remote-desktop on Gentoo with clang 16. Relevant bug: https://bugs.gentoo.org/885875.

Minimal reproducible code:

struct AUDIO_FORMAT
{
	char* data;
};

typedef struct AUDIO_FORMAT AUDIO_FORMAT;

static const AUDIO_FORMAT audio_format_aac = { 0 };

static AUDIO_FORMAT server_formats[] =
{
  audio_format_aac,
};

With Clang, I get the following output

test.c:12:3: error: initializer element is not a compile-time constant
  audio_format_aac,
  ^~~~~~~~~~~~~~~~
1 error generated.

While with GCC, it builds successfully.

Metadata

Metadata

Assignees

No one assigned

    Labels

    cclang:frontendLanguage frontend issues, e.g. anything involving "Sema"enhancementImproving things as opposed to bug fixing, e.g. new or missing feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions