<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/120197>120197</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Cannot compare std::string's in if constexpr
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Fedr
</td>
</tr>
</table>
<pre>
This program
```c++
#include <string>
struct A {
static constexpr std::string name() { return "a"; }
};
template<class T>
bool f( T && ) {
if constexpr ( T::name() == "a" )
return true;
else
return false;
}
int main() {
return f( A{} );
}
```
is accepted by GCC and MSVC, but Clang complains:
```
error: constexpr if condition is not a constant expression
9 | if constexpr ( T::name() == "a" )
| ^~~~~~~~~~~~~~~~
```
Online demo: https://gcc.godbolt.org/z/o3nMx3zWj
Original discussion: https://stackoverflow.com/q/79283228/7325599
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJykk0-P4ygQxT9N-VKayC7iOD74kHbGexrNYVu7ZwwVh1kMWcA9fw772VfEbk265zgIyRLUK37vYWSMZnLMHdRPUJ8LuaSrD93AOhSj19-756uJeAt-CnKG8gSHcp0K6CnP8gQkjFN20Ywg-piCcROIj3mnPMUUFpXwhNDkWkTEmGQyCpV3MfG3W8CYNIgTiNOqRSdnBjoCtVmFgdMSHAKRBCIQTwjNGTH3b84gntaDEs83KxOD6JWVMeLzyjB6b_ECdMRnBDoAHXBrvOGYywPKvW6FeaQQZxDnV4Ks37R5bHgpLLzC5EW2kX-tuci8vBI355XbuISzNO6n4U33qslIp7zcnO8nP8pfLyP3iSiV4ltijeN3_KPvUTqNn_78qwfqcVwS9la6CZXPQRkXs823PTgEH0CcHgJZ09EmGe_QRHQ-oVz3pUuYazhG491GnR30-Pu55i5Qf_zv7XjH-9lZ4xg1zz5TX1O63V3RADRMSu0mr0dv086HCWj4ATR44T59Ez_-_rKm_zmYyThpUZuoltXIL51ikuof_8LhYv3XnfIz0PAv0NC0dBSUrQyNoLpuM36hO6Fb0cqCu6oR-z0J0ZTFtWtbHuvjsa6Idbk_XNpatkpJ3ZZcHlumwnRU0r6iqimP1aEqd5Uamcd2FFK3WigN-5JnaezO2pc5eypMjAt3FZVV2xRWjmzj_SETOf6K9938ZOpzEbos-jAuU4R9aU1M8WebZJLlrpcu327-P2Tg968SqIlo3JtrLZZgu3epm3Rdxi2kfMD2-XAL_gurBDTcsSLQsHG_dPR_AAAA__-4HVTO">