<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/141797>141797</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
`[[gnu::weak]]` disables constant evaluation of constexpr variables in C++14
</td>
</tr>
<tr>
<th>Labels</th>
<td>
good first issue,
c++11,
c++14,
clang:frontend,
diverges-from:gcc
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
cor3ntin
</td>
</tr>
</table>
<pre>
GCC and Clang disagree on their handling of `[[gnu::weak]]` before C++17 https://gcc.godbolt.org/z/s7q67vqjz
```cpp
struct S { static constexpr int var = 0; };
[[gnu::weak]] constexpr int S::var;
static constexpr int usage = S::var;
```
While it would be unsafe to constant-fold this code, it should be fine to constant-evaluate it, for consistency with GCC
In `static bool evaluateVarDeclInit` (ExprConstant.cpp), and in `static bool CheckWeak` (`Interp.cpp`), we should allow constant evaluation -without diagnostics, but not constant folding) - by looking at `Info.EvalMode`
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyEU8GO2zgM_Rr5QiRwJMeODz4kTlPMYU8FtmdZpm11NGIq0U6nX79QksnsTrsoIMCA-R759MSnY7SjR2zE9iC2x0zPPFFoDAXl2fqso_61-dy2oH0PrdN-hN5GPQZEIA88oQ0wad8760egAUSZX1sdRj8LtRdqf0H9LLbHdMocOhwoILRCHoQ8bCqYmM8xIeVJyNNozHqkviPHawqjkKefQp5i9b2slu_ffop8n06Z3445n0W-jxxmw_AFRHWAyJqtAUM-Mv44B7CeYdEBhDpCLtQBRHUU6pDa_J_OD-wvt_qiw4332xFz1CNeh3yEP9TexH-drEOwDBeaXQ8dwuyjHhCYbi2159VArgeebARDPQrZJkKc3hiD9f_F46LdrDn1TeCBwrVmI6M3r3CxPMHntr0pePLple636IgcvNH_1uGIxj15y-mthNx9-nEO7X3KOtkt6zQgbYP9pU07oXn-mmy8kUWZP3nGcL4yy_xOvuDbVbRzdHnc4k2GJQ-rJJlmht7q0VNka2LidjODJ37nJKesH4WsAVbQvYIjek67qBmu8wdaf1q0-yv5WOZZ36i-VrXOsNlUxa4o6mJTZFODqjZ1KZXBvpBFuVO9UdVOb8rBmK42u8w2MpfbfCt3m1IqVay7zihd6lrnQy53eSGKHF-0dWvnlpe0vJmNccZmU2yqusqc7tDFa86kHIl6GGyIDFeQkFLIVkhp7rnY_PKneP-TYijUfgjkGX3_KPR2wTBiXA2BXoTaj8ak2vaYhSaJWnXzGEWROxs5vstkyw6bPwU3xb5zGH_7XDT8Kw6LDvYGtf4R9CKbg2s-hN3yNHdrQy9CnpKc-2d1DvQNDQt5uroThTzdXVwa-U8AAAD__yNBe7I">