<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/119271>119271</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang fails deduction on array when adding const qualification
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
brevzin
</td>
</tr>
</table>
<pre>
To be honest, I'm not entirely sure that this is a clang bug (and @zygoloid can put me in my place quickly enough).
Here's an interesting example:
```cpp
using size_t = decltype(sizeof(0));
template <size_t N>
void f(const int* const (&)[N]);
template <class T>
void g(T const* const*);
int main() {
int* pointers[3];
f(pointers); // clang: error, gcc: ok
g(pointers); // clang, gcc: ok
const int* const (&h)[3] = pointers; // clang, gcc: ok
}
```
All three of these situations seem similar: we're taking an array of pointers to mutable `int` (no `const` anywhere) and trying to add `const` in two layers:
* `f` is trying to deduce a reference to an array of const pointers to const `int` (gcc is okay with this, clang fails deduction saying it cannot match `const int *` against `int*`)
* `g` is trying to deduce a pointer to const pointer to const `int` (which is similar, and both gcc and clang are fine with this)
* `h` is just directly binding the same reference that `f` would have, except not in a template deduction context (likewise similar, both gcc and clang are fine with this too)
At the very least, it seems like `f` and `h` should either both be valid or both be invalid. So I think it's either a clang bug (so I'm in the right spot) or a C++ bug (and I should be writing this issue in a different spot).
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMlc2O2zYQx5-GvgxiyNTasg8-aHe7aC65NPeCosYiY4pUyJEd5emLoWyv0iZtAQOGKM5_fvMplZLtPOJRbJ_F9nWlRjIhHpuIl-_Wr5rQTsfPARoEEzwmEvIFPgpZ9eADAXqyEd0EaYwIZBQBGZvAJlCgnfIdNGMHQu6Vb0E8Fd-nLrhgW9DKwzAS9AjWQz_B4JRG-DpafXYToA9jZ4Q8rEVRi6L-HSMKWSVQHqwnjJjI-g7wm-oHh6Ks53tiV8w_PQyiqMfEl5L9jn8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