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

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <ja...@gcc.gnu.org>:

https://gcc.gnu.org/g:8dedf065aff22b09bd4e48e1be0b77c58d297100

commit r12-5537-g8dedf065aff22b09bd4e48e1be0b77c58d297100
Author: Jakub Jelinek <ja...@redhat.com>
Date:   Fri Nov 26 10:11:13 2021 +0100

    c++: Fix up taking address of an immediate function diagnostics [PR102753]

    On Wed, Oct 20, 2021 at 07:16:44PM -0400, Jason Merrill wrote:
    > or an unevaluated operand, or a subexpression of an immediate invocation.
    >
    > Hmm...that suggests that in consteval23.C, bar(foo) should also be OK,

    The following patch handles that by removing the diagnostics about taking
    address of immediate function from cp_build_addr_expr_1, and instead
diagnoses
    it in cp_fold_r.  To do that with proper locations, the patch attempts to
    ensure that ADDR_EXPRs of immediate functions get EXPR_LOCATION set and
    adds a PTRMEM_CST_LOCATION for PTRMEM_CSTs.  Also, evaluation of
    std::source_location::current() is moved from genericization to cp_fold.

    2021-11-26  Jakub Jelinek  <ja...@redhat.com>

            PR c++/102753
            * cp-tree.h (struct ptrmem_cst): Add locus member.
            (PTRMEM_CST_LOCATION): Define.
            * tree.c (make_ptrmem_cst): Set PTRMEM_CST_LOCATION to
input_location.
            (cp_expr_location): Return PTRMEM_CST_LOCATION for PTRMEM_CST.
            * typeck.c (build_x_unary_op): Overwrite PTRMEM_CST_LOCATION for
            PTRMEM_CST instead of calling maybe_wrap_with_location.
            (cp_build_addr_expr_1): Don't diagnose taking address of
            immediate functions here.  Instead when taking their address make
            sure the returned ADDR_EXPR has EXPR_LOCATION set.
            (expand_ptrmemfunc_cst): Copy over PTRMEM_CST_LOCATION to
ADDR_EXPR's
            EXPR_LOCATION.
            (convert_for_assignment): Use cp_expr_loc_or_input_loc instead of
            EXPR_LOC_OR_LOC.
            * pt.c (tsubst_copy): Use build1_loc instead of build1.  Ensure
            ADDR_EXPR of immediate function has EXPR_LOCATION set.
            * cp-gimplify.c (cp_fold_r): Diagnose taking address of immediate
            functions here.  For consteval if don't walk THEN_CLAUSE.
            (cp_genericize_r): Move evaluation of calls to
            std::source_location::current from here to...
            (cp_fold): ... here.  Don't assert calls to immediate functions
must
            be source_location_current_p, instead only constant evaluate
            calls to source_location_current_p.

            * g++.dg/cpp2a/consteval20.C: Add some extra tests.
            * g++.dg/cpp2a/consteval23.C: Likewise.
            * g++.dg/cpp2a/consteval25.C: New test.
            * g++.dg/cpp2a/srcloc20.C: New test.

Reply via email to