-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Closed as duplicate of#87867
Closed as duplicate of#87867
Copy link
Labels
c23clang:frontendLanguage frontend issues, e.g. anything involving "Sema"Language frontend issues, e.g. anything involving "Sema"duplicateResolved as duplicateResolved as duplicate
Description
I was attempting to create a generic bit cast macro using the new C23 typeof feature. Clang appears to reject the following code with "error: initializer element is not a compile-time constant" even though I believe this code is valid in C23. Both GCC and MSVC (with /std:clatest) accept this code.
#include <stdint.h>
#define bitcast(type, value) \
(((union{ typeof(value) src; type dst; }){ (value) }).dst)
int main(void)
{
int64_t foo = 4;
double bar = bitcast(double, foo); // ok
foo = bitcast(int64_t, bar); // ok
foo = bitcast(int64_t, bitcast(double, foo)); // error
return 0;
}Compiler Flags: -std=c23 -pedantic
Metadata
Metadata
Assignees
Labels
c23clang:frontendLanguage frontend issues, e.g. anything involving "Sema"Language frontend issues, e.g. anything involving "Sema"duplicateResolved as duplicateResolved as duplicate