<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/66599>66599</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            wrong type of ternary expression involving composite pointer type with array of unknown bound
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          leni536
      </td>
    </tr>
</table>

<pre>
    Version: clang 16.0.0
flags: `-std=c++20 -O2 -pedantic-errors`

### Observed behavior

```cpp
template <typename T>
void f();

void foo() {
    decltype(auto) ptr
 = true
      ? (int(*)[42])nullptr
      : (int(*)[])nullptr;
 f<decltype(ptr)>(); // calls f<int const (*) []>()
}
```

https://godbolt.org/z/TvaqEKr4v

### Expected behavior

The type of the ternary expression should be `int (*)[]`.

It seems that clang is overeager in applying https://timsong-cpp.github.io/cppwp/n4868/conv.qual#3.3 .
$P_1^3$ is different from one of the source $P_1$-s, which means that `const` is added for every $cv_k$ for $0 < k < 1$, which should be none of them. I think clang treats the right bound as inclusive here when the difference between the two types is in $P_i$.

### Notes

* GCC doesn't implement bringing ternary arguments to composite pointer type when array of unknown bound is involved https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100189.
* The conversions with array of unknown bound were added in [P0388](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0388r4.html).
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx0VU1vpDgQ_TXuS6kRmI80hz6k02E1WmlnDqO9joypBk-MzdgGpufXrwpIOskmEiJAVT2_V_VSLbxXrUE8svzE8vNOjKGz7qjRqDwtdrVtrsd_0XllDUvvQWphWkiKKI5iFp9ZfH_RovUUYkW896Fh6VkyfmL8xGPYf-WwH7ARJii5R-es86zYKrc7T9cLvtYe3YQN1NiJSVn3Jq2I10sOw_olYD9oERBY-hCuAxrRI3xn6eManqxq4ML4gfGSpafXW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