<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/62136>62136</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Clang] Cannot use static constexpr member variable in constant expression
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
craffael
</td>
</tr>
</table>
<pre>
## Clang Version:
```
clang version 17.0.0 (https://github.com/llvm/llvm-project.git 27f27d15f6c90b026eca23b8ee238fdbf772fd80)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/compiler-explorer/clang-trunk/bin
```
## Steps to reproduce
Try to compile the following simple program with `clang++-16 -std=c++20 source.cc` ( see also [godbolt](https://godbolt.org/z/1bsazYvK7):
```
struct Mesh {
static constexpr int kDimMesh = 3;
};
void checkMesh(const Mesh& mesh) {
constexpr auto kDimMesh = mesh.kDimMesh;
}
int main() {
Mesh mesh;
checkMesh(mesh);
}
```
Error Message:
```
<source>:6:18: error: constexpr variable 'kDimMesh' must be initialized by a constant expression
constexpr auto kDimMesh = mesh.kDimMesh;
^ ~~~~~~~~~~~~~
<source>:6:29: note: function parameter 'mesh' with unknown value cannot be used in a constant expression
constexpr auto kDimMesh = mesh.kDimMesh;
^
<source>:5:28: note: declared here
void checkMesh(const Mesh& mesh) {
^
1 error generated.
```
As far as I can tell, this is perfectly valid c++ and it compiles fine with gcc and MSVC.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVc1u4zYQfprxZWBBIm1JPvjgxDGwKPa0xQI9FRQ1kthQpEBSTrKHPntBytk4u06BLkoIkji_3wyHM8J71RuiPWzvYHtciTkM1u2lE10nSK8a277sgXFgHO-1MD1-JeeVNcAPkB8hP0CZX560lUnovAhhUWV5liOweghh8lGJnYCdehWGucmkHYGdtD6_ftaTs3-RDFmvArKqY1VbbLtS7vImZyVJwXhTEzFed23TVRX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