On Fri, Mar 30, 2018 at 3:48 AM, Alexandre Oliva <aol...@redhat.com> wrote:
> On Mar 29, 2018, Alexandre Oliva <aol...@redhat.com> wrote:
>
>> Here's a patch that should take care of the marking a namespace-scoped
>> or static member function as used when taking its address, thus working
>> around (fixing?) the reported problem.
>
>> Regstrapping now.  Ok to install if it passes?
>
> It regressed overload/template1.C, because we mark an erroneous template
> specialization as used when we attempt deduction.
>
> The following updated patch avoids that regression, and it has passed
> bootstrap and regression testing on i686- and x86_64-linux-gnu.  Ok to 
> install?
>
> [PR c++/84943] mark function as used when taking its address
>
> fn[0]() ICEd because we would fold the INDIRECT_REF used for the
> array indexing while building the address for the call, after not
> finding the decl hiding there at first.  But the decl would be exposed
> by the folding, and then lower layers would complain we had the decl,
> after all, but it wasn't one of the artificial or special functions
> that could be called without being marked as used.
>
> This patch arranges for a FUNCTION_DECL to be marked as used when
> taking its address, just like we already did when taking the address
> of a static function to call it as a member function (i.e. using the
> obj.fn() notation).  However, we shouldn't mark functions as used when
> just performing overload resolution, lest we might instantiate
> templates we shouldn't, as in g++.dg/overload/template1.C.
>
>
> for  gcc/cp/ChangeLog
>
>         PR c++/84943
>         * typeck.c (cp_build_addr_expr_1): Mark FUNCTION_DECL as
>         used.
>
> for  gcc/testsuite/ChangeLog
>
>         PR c++/84943
>         * g++.dg/pr84943.C: New.
>         * g++.dg/pr84943-2.C: New.
> ---
>  gcc/cp/typeck.c                  |    9 +++++
>  gcc/testsuite/g++.dg/pr84943-2.C |   64 
> ++++++++++++++++++++++++++++++++++++++
>  gcc/testsuite/g++.dg/pr84943.C   |    8 +++++
>  3 files changed, 80 insertions(+), 1 deletion(-)
>  create mode 100644 gcc/testsuite/g++.dg/pr84943-2.C
>  create mode 100644 gcc/testsuite/g++.dg/pr84943.C
>
> diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
> index d3183b5321d3..f6b25c8a837d 100644
> --- a/gcc/cp/typeck.c
> +++ b/gcc/cp/typeck.c
> @@ -5831,6 +5831,8 @@ cp_build_addr_expr_1 (tree arg, bool strict_lvalue, 
> tsubst_flags_t complain)
>    if (type_unknown_p (arg))
>      return build1 (ADDR_EXPR, unknown_type_node, arg);
>
> +  tree maybe_overloaded_arg = arg;

I don't think we need this; if arg is overloaded, we take the
type_unknown_p early exit, so the code lower down is always dealing
with a single function.

Jason

Reply via email to