clang 18 incorrectly reports an error declaring an enum as the result of a compile-time evaluated integer expression.
reduced test case below. clang version 18.1.8 Target: x86_64-pc-linux-gnu
#include <iostream>
#include <memory>
struct B { int i; };
struct A {
constexpr A(int i) { std::construct_at(__builtin_addressof(b), i); }
constexpr ~A() { std::destroy_at(__builtin_addressof(b)); }
union { B b; };
};
consteval int i() { return A{42}.b.i; } // wrapper to circumvent compiler bug
int main() {
// enum { I = i() }; // no error with both clang and gcc
enum { I = A{42}.b.i }; // error with clang, but not with gcc
std::cout << I << '\n';
}