https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100189
Bug ID: 100189
Summary: rejects valid conditional operators involving
conversions to arrays of unknown bound (P0388)
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: leni536 at gmail dot com
Target Milestone: ---
Version: g++ (Compiler-Explorer-Build) 12.0.0 20210420 (experimental)
Flags: -std=c++20 -O2 -pedantic-errors
Consider the following snippet:
```
void foo() {
auto ptr = true
? (int (*)[]) nullptr
: (int (*)[42]) nullptr;
}
```
https://godbolt.org/z/nKbzvaY3h
Since the third argument is convertible to the second argument, but not the
other way around, this should be accepted.
https://timsong-cpp.github.io/cppwp/n4861/expr.cond#4.3.3
Also consider the following snippet:
```
template <typename T>
using pointer_to = T*;
template <typename T>
using array_of_ub = T[];
template <unsigned long long N,
typename T>
using array_of = T[N];
void foo() {
using t1 =
pointer_to<
array_of_ub<
pointer_to<
array_of<10,
int
>>>>;
using t2 =
pointer_to<
array_of<10,
pointer_to<
array_of_ub<
int
>>>>;
auto ptr = true
? (t1)nullptr
: (t2)nullptr;
}
```
https://godbolt.org/z/s1rnher9G
This should also be accepted following
https://timsong-cpp.github.io/cppwp/n4861/expr.cond#7.3 and
https://timsong-cpp.github.io/cppwp/n4861/expr.type#3.5 . I am a bit less sure
about this one, but I believe the type of `ptr` in this case should be
`pointer_to<const array_of_ub<pointer_to<array_of_ub<int>>>>` after applying
https://timsong-cpp.github.io/cppwp/n4861/conv.qual#3 and removing a redundant
`const`.