On Fri, 15 May 2026, Eczbek wrote: > Hello, I am looking for feedback on this patch. It additionally allows > `&(A::operator int)` to compile, and I'm not sure how to fix this. > Bootstrapped/regtested on x86_64-pc-linux-gnu.
We also already incorrectly accept &(A::f<int>), because we pass a BASELINK instead of a FUNCTION_DECL to build_offset_ref which suppresses the "invalid use of non-static member function" it seems. > > -- >8 -- > > From 3577df94d250407f322ce9fd2e77667dc625f803 Mon Sep 17 00:00:00 2001 > From: Eczbek <[email protected]> > Date: Fri, 15 May 2026 11:45:07 -0400 > Subject: [PATCH] c++: Fix taking address of conversion operator template > instantiation [PR122383] > > PR c++/122383 > > gcc/cp/ChangeLog: > > * pt.cc (resolve_nondeduced_context): If expr is a conversion > operator template instantiation, call lookup_template_function, > then fall through to TEMPLATE_ID_EXPR. > > gcc/testsuite/ChangeLog: > > * g++.dg/cpp/pr122383.C: New test. > --- > gcc/cp/pt.cc | 11 ++++++++++- > gcc/testsuite/g++.dg/cpp/pr122383.C | 18 ++++++++++++++++++ > 2 files changed, 28 insertions(+), 1 deletion(-) > create mode 100644 gcc/testsuite/g++.dg/cpp/pr122383.C > > diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc > index 42e82e305aa..db8ac48ff58 100644 > --- a/gcc/cp/pt.cc > +++ b/gcc/cp/pt.cc > @@ -25361,7 +25361,16 @@ resolve_nondeduced_context (tree orig_expr, > tsubst_flags_t complain) > baselink = expr; > expr = BASELINK_FUNCTIONS (expr); > } > - > + if (TREE_CODE (expr) == OVERLOAD > + && IDENTIFIER_CONV_OP_P (OVL_NAME (expr))) Does this do the right thing if we have a non-template and template overload: strut A { operator int(); template<class T> operator T(); }; > + { > + if (tree conv_type = BASELINK_OPTYPE (baselink)) > + { > + tree targs = make_tree_vec (1); > + TREE_VEC_ELT (targs, 0) = conv_type; > + expr = lookup_template_function (expr, targs); > + } > + } > if (TREE_CODE (expr) == TEMPLATE_ID_EXPR) > { > int good = 0; > diff --git a/gcc/testsuite/g++.dg/cpp/pr122383.C > b/gcc/testsuite/g++.dg/cpp/pr122383.C > new file mode 100644 > index 00000000000..074195abd61 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp/pr122383.C > @@ -0,0 +1,18 @@ > +// PR c++/122383 > +// { dg-do compile } > + > +struct A { > + template<typename T> > + operator T() { > + return 0; > + } > +}; > + > +template<typename U> > +void f(U(A::*)()) {} > + > +int main() { > + &A::operator int; > + > + f(&A::operator int); > +} > -- > 2.54.0 > >
