Skip to content

getting: "error: initializer element is not a compile-time constant" Even when struct is inside function #87867

Closed
@aalmkainzi

Description

@aalmkainzi
int foo(int *a, int b)
{
    return 0;
}

int main()
{
    int x;
    (struct {
          typeof(foo(&(struct { int t; }){.t = x}.t, 0)) t;
        }){0};
}

the above code compiles with gcc and tcc. but fails with clang.

The error I get is:

err_test.c:10:48: error: initializer element is not a compile-time constant
          typeof(foo(&(struct { int t; }){.t = x}.t, 0)) t;
                                               ^
1 error generated.

This error seems to be for global or static variables, but for some reason is triggering even though the variable is defined inside a function and inside a typeof

Metadata

Metadata

Assignees

No one assigned

    Labels

    c23clang:frontendLanguage frontend issues, e.g. anything involving "Sema"confirmedVerified by a second party

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions