<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/123498>123498</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang-trunk fails to compile valid code
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
beached
</td>
</tr>
</table>
<pre>
It looks like a recent change has broken the following code and it is instantiating the else branch of an if constexpr
https://gcc3.godbolt.org/z/YvKjrEKsG
```cpp
#include <cstddef>
#include <functional>
#include <type_traits>
template <typename T>
struct remove_array_ref;
template <typename T, std::size_t N>
struct remove_array_ref<T (&)[N]> {
using type = T[N];
};
template <typename T>
using remove_array_ref_t = typename remove_array_ref<T>::type;
template <typename T, typename Compare = std::equal_to<>,
typename U = std::enable_if_t<std::is_array_v<remove_array_ref_t<T>>,
remove_array_ref_t<T>>>
constexpr bool array_cmp(T && lhs, T &&rhs, Compare const &cmp = Compare{}) {
for (size_t n = 0; n < std::extent_v<U>; ++n) {
if constexpr (std::rank_v<U> == 1) {
if (not cmp(lhs[n], rhs[n])) {
return false;
}
} else {
if (not array_cmp(lhs[n], rhs[n], cmp)) {
return false;
}
}
}
return true;
}
int main() {
{
constexpr int ints1[]{1, 2, 3, 4};
constexpr int ints2[]{1, 2, 3, 4};
static_assert(array_cmp(ints1, ints2));
}
{
constexpr int ints3[2][4]{{1, 2, 3, 4}, {1, 2, 3, 4}};
constexpr int ints4[2][4]{{1, 2, 3, 4}, {1, 2, 3, 4}};
static_assert(array_cmp(ints3, ints4));
}
}
```
```
<source>:25:21: error: no matching function for call to 'array_cmp'
25 | if (not array_cmp(lhs[n], rhs[n], cmp)) {
| ^~~~~~~~~
<source>:37:23: note: in instantiation of function template specialization 'array_cmp<const int (&)[4], std::equal_to<void>, const int[4]>' requested here
37 | static_assert(array_cmp(ints1, ints2));
| ^
<source>:18:16: note: candidate template ignored: substitution failure [with T = const int &, Compare = std::equal_to<void>]: implicit instantiation of undefined template 'remove_array_ref<const int &>'
13 | using remove_array_ref_t = typename remove_array_ref<T>::type;
| ~~~~~
14 |
15 | template <typename T, typename Compare = std::equal_to<>,
16 | typename U = std::enable_if_t<std::is_array_v<remove_array_ref_t<T>>,
17 | remove_array_ref_t<T>>>
18 | constexpr bool array_cmp(T && lhs, T &&rhs, Compare const &cmp = Compare{}) {
| ^
<source>:37:23: error: static assertion expression is not an integral constant expression
37 | static_assert(array_cmp(ints1, ints2));
| ^~~~~~~~~~~~~~~~~~~~~~~
<source>:42:23: error: static assertion expression is not an integral constant expression
42 | static_assert(array_cmp(ints3, ints4));
| ^~~~~~~~~~~~~~~~~~~~~~~
3 errors generated.
Compiler returned: 1
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy8V09v2zoS_zT0ZdBAIi3LPvhgK8li8YB3ag97MihqbLOhSZek0qaHfvbFiLKs2EmaXaSPCBTRnD-_35AzQ8kQ9M4iLlmxZsXtRLZx7_yyRqn22Exq1zwt_x3BOPcQwOgHBAkeFdoIai_tDmEvA9TePaCFuEfYOmPcd213oFyDIG0DOoIOoG2I0kYtIy2SKJqAUHtp1R7cFqQFvQXlbIj44-iBZat9jMfAxIrxe8bvd0qJm51ramfijfM7xu9_Mn7_n8e_vvq7v8K_WLaiv1mW_tTxSFMutFWmbRCYqFSITYNbJu6ulratVVE7K81Lq_HpiJvopY6hX85WEQ9HI-OwbuUB4XNaDtG3KoLHg3vEjfRePm08OV6_qcsrCLEhxmIV9E_cRPj7Nwarz8D4nPEZ4wtWrP9mxS0Td8BK8gQA0IYu4E9HcnYLnwehDkrZv7xFJlm4dL2Jnb1B-CVopN-RIal3kB9mlTscpU-Ih4jgt1aaTXRMVGSYVz3DNAbdLxdaVtYGN3q7iUxUw8869FAfmaiuuQ3oT37eFOnCdD66tXMGkqQ6HBmf0x7NGJ-B2QfieZr7ND2x7SzQkjocOxL9Am1mecv4YrStW-dp4_tTYjvxjIl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