On Sat, 16 Sep 2023, Jason Merrill wrote: > On 9/15/23 13:55, Patrick Palka wrote: > > This corrects decltype of a (class) NTTP object as per > > [dcl.type.decltype]/1.2 and [temp.param]/6 in the type-dependent case. > > In the non-dependent case (nontype-class8.C) we resolve the decltype > > ahead of time, and finish_decltype_type already made sure to drop the > > const VIEW_CONVERT_EXPR wrapper around the TEMPLATE_PARM_INDEX. > > Hmm, seems like dropping the VIEW_CONVERT_EXPR is wrong in this case? I'm not > sure why I added that.
Ah sorry, my commit message was a bit sloppy. In the non-dependent case we resolve the decltype ahead of time, in which case finish_decltype_type drops the const VIEW_CONVERT_EXPR wrapper around the TEMPLATE_PARM_INDEX, and the latter has the desired non-const type. In the type-dependent case, tsubst drops the VIEW_CONVERT_EXPR because the substituted class NTTP is the already const object created by get_template_parm_object. So finish_decltype_type at instantiation time sees the bare const object, which this patch now adds special handling for. So we need to continue dropping the VIEW_CONVERT_EXPR to handle the non-dependent case. > > Jason > >