-
Notifications
You must be signed in to change notification settings - Fork 11.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
getting: "error: initializer element is not a compile-time constant" Even when struct is inside function #87867
Comments
@llvm/issue-subscribers-clang-frontend Author: Abdulmalek Almkainzi (aalmkainzi)
```C
int foo(int *a, int b)
{
return 0;
}
int main()
err_test.c:10:48: error: initializer element is not a compile-time constant
|
However if we change This makes a lot more sense, although the |
Why would x be required to be constant in this context? |
It's not required to be a constant in this case. The compound literal is at block scope and so the initializer does not need to be constant (C23 6.5.3.6p4). The issue is that we're checking for file scope at llvm-project/clang/lib/Sema/SemaExpr.cpp Line 7863 in f6357bb
|
shouldn't also work for file scope? since the compound literal is inside a |
There are no special allowances for initialization that occurs in an unevaluated context, so being inside of |
the above code compiles with gcc and tcc. but fails with clang.
The error I get is:
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
The text was updated successfully, but these errors were encountered: