<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/59520>59520</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Dependent static_assert fails inside if constexpr
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang:frontend,
rejects-valid
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
ldionne
</td>
</tr>
</table>
<pre>
The following doesn't compile, but it seems like it should:
```
cat <<EOF | clang++ -xc++ - -std=c++20 -fsyntax-only
#include <type_traits>
template <typename T>
void f() {
auto lambda = []<typename U>(U) {
if constexpr (std::is_same_v<T, bool> && std::is_same_v<U, int>) {
static_assert(std::is_same_v<T, bool>);
}
};
lambda(0);
}
int main() {
f<long>();
}
EOF
```
Fails with:
```
<stdin>:7:4: error: static assertion failed due to requirement 'std::is_same_v<long, bool>'
static_assert(std::is_same_v<T, bool>);
^ ~~~~~~~~~~~~~~~~~~~~~~~
<stdin>:14:2: note: in instantiation of function template specialization 'f<long>' requested here
f<long>();
^
1 error generated.
```
It seems like this should work since the `if constexpr` condition is dependent on `T`?
Godbolt: https://godbolt.org/z/jf7hWdYWz
GCC accepts this. MSVC fails like Clang.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykVM-PozYU_mteLk-JHJsEOHDIkKHqodpDZ7vqaeTgR_CusVNs5tehf3tlYDLJNruqVISMbd6v7_vsJ73XR0tUwOYONvuFHELr-sIo7aylxcGp1-KhJWycMe5Z2yMqR94CTwPWrjtpQ8BLPAwBdUBP1Hk0-huNq9YNRoHYAdsDex-3bH7HZS0DgihBlPefKoS0xNpIewR-B_wOly_1-wyXPigQ-3mDM1w2_tUG-bJ01rzOwbnQtjaDohg0vJ7oMfRSBw_i_rKIQN3JyHC2srIjfDgbPTmtsAGeAc8R0rt311wOwaGR3UFJBLHHibTLIJ9jEJ59_t4TWK4brJ31gV5OPQLPRjw7EDvtH73s6PE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