<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/82891>82891</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Calling a static constexpr method on a non-constexpr variable does not yield a constexpr result
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
eyelash
</td>
</tr>
</table>
<pre>
The following C++ code fails to compile with Clang 17.0.1:
```cpp
struct A {
static constexpr int n() {
return 42;
}
};
void foo(const A& a) {
constexpr int n = a.n();
}
```
with the following error message:
```
<source>:8:19: error: constexpr variable 'n' must be initialized by a constant expression
8 | constexpr int n = a.n();
| ^ ~~~~~
<source>:8:23: note: function parameter 'a' with unknown value cannot be used in a constant expression
8 | constexpr int n = a.n();
| ^
<source>:7:19: note: declared here
7 | void foo(const A& a) {
| ^
```
GCC compiles the same code without errors.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0lE2SqzYQx0_TbLqGAmEMLFj4Y5wL5AJCahslQnLpw46zyNlTAnv8nLyZms1TUQIkdbd-f3WLe69OhqiHegv1PuMxjNb1dCPN_ZgNVt7630fCo9XaXpU54Q7YFtgWhZWER660x2BR2OmsNOFVhRF3mpsTlk1e5CVUGyj2UDz6dbE84nxeRnxwUQTcIDTbZQQR0QcelEBhjQ_019mhMgENsBZY97oyNUchOoMrBtUPM9Ds70Gb_cfE0l-skni0Flg7h8ANsDXyV-f_CY5Q7ZHn9008HX5EeaD9GGjWI7wISM5ZhxN5z0_0mTz332rnbXSCoHqHatNCtSk7qDaLj_Tx3OOFO8UHTQisMcAanKIPOBAqo4LiWv1NEocb8sWGm4DJjrxX1jxFaxGa3Szq9_CXA3jYvDao3xHxn9Q-5WFVwjA2JCnwGI0Iyho8c8cnCuQSDk84s5LR_Gns1eCF60gouDF2ZoyeJCrz6-Cgfv8pQvNxJA8ESUJzRxJHcvR008xuvpV3Xyv6RbL9tts9CtHPSef5REuhJvVsDEvi-DyTfSW7quMZ9WVTtE23Luo6G_u2EqxZy1J2tC74INq6KIqVZG3ZSlHV60z1rGCrgrFV2VSrss6p7goi2XTDcd0eeQWrgiaudK71ZcqtO2XK-0h9y9quzDQfSPv5tmHM0BXnSWAsXT6uTzZvQzx5WBVa-eCfXoIKmvod1zoVEf__DTFRGK1Em7LAWPP2k9KQlnw6KLwp0vKRLfMaRz7qkEWn-zGEs0-FyQ7ADicVxjjkwk7ADmk399fb2dk_SARgh5nBAzvMjP8GAAD__7b9js0">