Hi Martin,

On Fri, May 12, 2023 at 12:13 PM Martin Jambor <mjam...@suse.cz> wrote:
>
> Hello Patrick,
>
> On Wed, May 03 2023, Patrick Palka via Gcc-patches wrote:
> >
> [...]
> >
> > Subject: [PATCH] c++: potentiality of templated memfn call [PR109480]
> >
> > Here we're incorrectly deeming the templated call a.g() inside b's
> > initializer as potentially constant, despite g being non-constexpr,
> > which leads to us wastefully instantiating the initializer ahead of time,
> > which incidentally tiggers a bug in access checking deferral (to be
> > fixed by the subsequent patch).
> >
> > This patch fixes this by calling get_fns earlier during CALL_EXPR
> > potentiality checking so that we're able to extract a FUNCTION_DECL out
> > of a templated member function call (whose overall is typically a
> > COMPONENT_REF) and to the usual checking if the called function is
> > constexpr etc.
> >
> > In passing, I noticed potential_constant_expression_1's special handling
> > of the object argument of a non-static member function call is effectively
> > the same as the generic argument handling a few lines later.  So this
> > patch just gets rid of this special handling; otherwise we'd have to adapt
> > it to handle templated versions of such calls.
> >
> >       PR c++/109480
> >
> > gcc/cp/ChangeLog:
> >
> >       * constexpr.cc (potential_constant_expression_1) <case CALL_EXPR>:
> >       Reorganize to call get_fns sooner.  Remove special handling of
> >       the object argument of a non-static member function call.  Remove
> >       dead store to 'fun'.
> >
>
> This patch makes g++ no longer accept the following, complaining that
> get_subsys is non-constexpr (with just -std=c++17 -S), which is of
> course auto-reduced from a much larger source file from Ceph:
>
> ----------------------------------- 8< -----------------------------------
> struct {
>   void get_subsys();
> } PriorSet_dpp;
> struct PriorSet {
>   template <typename> PriorSet();
> };
> template <typename> PriorSet::PriorSet() {
>   [](auto cctX) { cctX.template should_gather<PriorSet_dpp.get_subsys()>; };
> }
> ----------------------------------- 8< -----------------------------------
>
> I assume that is intentional and am actually somewhat surprised it was
> accepted before, but can you please confirm?

Yes, this seems correct/intentional to me-- no instantiation of the
template would be valid because it's trying to use a non-constant
expression (which we now correctly identify as such) as a template
argument, so this snippet is IFNDR.

I don't think we have testsuite coverage for this QoI diagnostic, I'll add one.

>
> Thanks,
>
> Martin
>

Reply via email to