<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/97266>97266</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang rejects regular constexpr member function in struct with virtual base class
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Rush10233
</td>
</tr>
</table>
<pre>
First, the following code is rejected by clang but accepted by other compilers like GCC, MSVC, and ICC:
```c++
struct base { };
struct derived : virtual base {
constexpr int tst(){return 1;}
};
```
[https://godbolt.org/z/rj63nKP4v](https://godbolt.org/z/rj63nKP4v)
Clang reports the following message:
```c++
<source>:3:23: error: constexpr member function not allowed in struct with virtual base class
3 | constexpr int tst(){return 1;}
| ^
<source>:2:22: note: virtual base class declared here
2 | struct derived : virtual base {
| ^~~~~~~~~~~~
1 error generated.
```
The diagnostic seems not such necessary because member function `tst` doesn't involve any override and can be specified during compile stage.
It's more interesting that the overloaded copy assignment operator is also accepted by other compilers, which definitely contains the instantiation of the virtual base class:
```c++
struct base { };
struct derived : virtual base {
//reject
//constexpr derived(const derived &)=default;
//reject
//constexpr derived(derived &&)=default;
//accept
constexpr derived& operator=(derived const&) =default;
};
```
[https://godbolt.org/z/rYPEYTex8](https://godbolt.org/z/rYPEYTex8)
Copy ctors and move ctors are always rejected though.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEVc1u4zYQfhr6MlhDJm3JOuiQ2HGxKAos2kWBPVLkWOKWIg1y5Kx76LMXpJw43qSpu5cSMmXxZ36_-UbGaDqH2LDVPVttZ3Kk3ofm1zH2i4ILMWu9PjU7EyIxvgHqEfbeWv9oXAfKawQTIeBXVIQa2hMoK10H7UgglcLDedVTjwGUHw7GYohgzR8IP202SeYvv_2e39Jp-LjZMHHHii0rnuaymB7F-H168ioAQKQwKoJWRgRW3QOrtky83tcYzBE1MHEHRxNolPb5zuVwGsq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