<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/113092>113092</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
incorrect compiler error "expression is not an integral constant expression" in enum declaration
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
djnz00
</td>
</tr>
</table>
<pre>
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';
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyEVMGOozgQ_RpzKQUZkyZw4JB0NtLe9x4Zu0I8MnZkl9Pde9hvXxnIJjM90koIsF31XlX56ckYzegQe_Z2YG_HQia6-tDrH-5vzovB669eWelGqFowTvkQUJH9goA3HyiCdIAh-AAalZXBuHHecmkCGYGuCAFjsgT-AhKUn27G4obMhIB3aZMk1GAc4YgB8PMWMEbjXcn4kfH98g6ok0INhJFAyYgwoPUfJSyV3THkFKjasipb-EuGEYnVe_hsm3Oz3dzUxhqXPjejS6-wrOHrsyxFbZyySSOw-t34SAHlxOo_fnc84eTD1_NwfkcKSREcgO0OuScwrM6LI6sPv4nb57hlB0B5Fyn3D3sm2iVZdDNSJM3qPav3c0xOPUtioj2fh2QsGXeWWue5-QsT7cBEx8T7nP6g_8bxTyb5hq8xUvBf_4_-K3Byef4Z6wDDt56_9b_UcZd2HdKzlICUgoM92x22gu2O5VA-ZghMnJg4wUeQtxsGIA_KBJWmOzp6CCvAkMZXqkwwSeOeHI-aV7hZqZn6T2D18aWYpeguP0uk86vSPwxdYfB0XfUnnYZRqQfwL4g_9fKCu9I_EWewfHNDInCelt0X4BcdJMoiZPX7TDL_MLFjb-8uf14n_7PSC93Xuqs7WWBf7US33VaiqYprX3et4BfJLxdeVU3XbXeCdy2vGtScc6UK0wsuthUXvGpExatS12-NrJXSiI2uJbItx0kaW1p7n0ofxsLEmLCvqpp3orByQBtnlxHC4QfMp0yIbDqhz0mbIY2Rbbk1keIThgxZ7P_znudVL7NjQjxtA0ycRyfd4ilB2kX10tGLuzAhwKwutfiWJONdkYLtr0S3mOc8X9Bo6JqGUvmJiVMuaf1sbsH_QEVMnOZGIhOntdN7L_4NAAD__781mnA">