https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92010

--- Comment #7 from Patrick Palka <ppalka at gcc dot gnu.org> ---
(In reply to Patrick Palka from comment #6)
> (In reply to Patrick Palka from comment #5)
> > The ICE seems to be revealing a latent issue:  In the following example
> > (which GCC accepts), according to the static_assert labelled (1), the type
> > of t is const int*, but according to the static_assert labelled (2), the
> > type of t is int *const.
> > 
> > 
> > 
> > template <typename T>
> > void foo(const T t)
> > {
> >   static_assert(__is_same(decltype(t), const int*));  // (1)
> > }
> > 
> > static_assert(__is_same(decltype(foo<int[]>), void(int *)));  // (2)
> > 
> > int
> > main()
> > {
> >   foo<int[]>(nullptr);
> > }
> 
> So the question becomes, what should the type of t be here?  According to
> https://eel.is/c++draft/temp#deduct-3:
> 
> "A top-level qualifier in a function parameter declaration does not affect
> the function type but still affects the type of the function parameter
> variable within the function."
> 
> The above suggests that the type of foo<int[]> should be the same regardless
> of where the parameter t is const-qualified.  Going by this then, it appears
> that the static_assert (2) is right and (1) is wrong.  Can anyone confirm?
> 
> (On the other hand, Clang thinks (1) is right and (2) is wrong.)

So I think the quoted wording from [temp.deduct]/3 applies to function
parameter types _after_ substitution.  So this doesn't definitively tell us
anything about the type of t.

I think the answer lies in [basic.type.qualifier]/3, which says:

"Cv-qualifiers applied to an array type attach to the underlying element type,
so the notation “cv T”, where T is an array type, refers to an array whose
elements are so-qualified ([dcl.array]"

So the type const T after substituting T=int[] is precisely const int[], which
as a parameter type then decays to const int* according to [dcl.fct]/5.  So it
seems that the static_assert (1) is right, and (2) is wrong.

Reply via email to