From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTPS id 8608A3858404 for ; Mon, 18 Oct 2021 16:42:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8608A3858404 Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-371-O4NKlfEDOzaU1-hDQhlbyg-1; Mon, 18 Oct 2021 12:42:02 -0400 X-MC-Unique: O4NKlfEDOzaU1-hDQhlbyg-1 Received: by mail-qv1-f72.google.com with SMTP id p9-20020a05621421e900b003830bb235fbso15314482qvj.14 for ; Mon, 18 Oct 2021 09:42:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=SKoIyQUeqY+iQJnG73CDCIXs8ZYjWHukR4Lpr3tsVmM=; b=j4KzlCXknVA8ia+5+UbCqd36Uv9fWxEAC59zsdUMZsJLNU1LD5azPlCaQh5evORqA8 tdKfQien9B3FYRV0jqFdunUZ1xfu51PAylyJJqSnvlrKEXNem5mSUqg9HfcJxP69kuec YXWUxOoqIbb1TMG+K5P7SsqWCCEix87qkBZzvN/1nJsJQ4jnPV83bout/oJPlUTSOHgH tCrTYnvUqMicUNI8FDGEvCsQy7fFQabGSFKBQJ7OQBadnL5cq03tLarZdZKq0XazeRMO Omd1jDvr7OGJ+/0/bW/V9gSSxioA3DCv7s3W7AD2uBczNdG6FLZFFy72Q0sCEzgw3OhF wGKg== X-Gm-Message-State: AOAM533ZOWdc7gSNDogyDdipwle+SmUqeml+TJ2egGSd8YhIQeltQ5mg EyMKSPVjIyls2SPUBDqeKAcKNXmZ1oZCR/Ko+gg3dvQ2xBjDBd7MUQLvzkIscZJ05EDkQzDHg15 HwCKSCS2cPdZUjotVKg== X-Received: by 2002:ac8:67c2:: with SMTP id r2mr31273915qtp.201.1634575321842; Mon, 18 Oct 2021 09:42:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw5wxpqemfSeC/QuG/Cg9Zkf6thxf5V39lxPJGMzuNQXnFSJyJ6M24M8BXB+aTBf6F3zRtk7Q== X-Received: by 2002:ac8:67c2:: with SMTP id r2mr31273897qtp.201.1634575321566; Mon, 18 Oct 2021 09:42:01 -0700 (PDT) Received: from [192.168.1.149] (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id s14sm7242931qtc.32.2021.10.18.09.42.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 18 Oct 2021 09:42:00 -0700 (PDT) Message-ID: <40b79f8d-dd22-a2f4-f63d-802d67395444@redhat.com> Date: Mon, 18 Oct 2021 12:42:00 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.0 Subject: Re: [PATCH] c++: Diagnose taking address of an immediate member function [PR102753] To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org References: <20211018081258.GV304296@tucnak> From: Jason Merrill In-Reply-To: <20211018081258.GV304296@tucnak> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, NICE_REPLY_A, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 18 Oct 2021 16:42:06 -0000 On 10/18/21 04:12, Jakub Jelinek wrote: > Hi! > > The following testcase ICEs, because while we have in cp_build_addr_expr_1 > diagnostics for taking address of an immediate function (and as an exception > deal with build_address from immediate invocation), I forgot to diagnose > taking address of a member function which is done in a different place. > I hope (s.*&S::foo) () is not an immediate invocation like > (*&foo) () is not, so this patch just diagnoses taking address of a member > function when not in immediate context. > > Bootstrapped/regtested on x86_64-linux and i686-linux (without go, > that seem to have some evrp issue when building libgo on both), ok for > trunk? > > 2021-10-18 Jakub Jelinek > > PR c++/102753 > * typeck.c (cp_build_addr_expr_1): Diagnose taking address of > an immediate method. Use t instead of TREE_OPERAND (arg, 1). > > * g++.dg/cpp2a/consteval20.C: New test. > > --- gcc/cp/typeck.c.jj 2021-10-05 09:53:55.382734051 +0200 > +++ gcc/cp/typeck.c 2021-10-15 19:28:38.034213437 +0200 > @@ -6773,9 +6773,21 @@ cp_build_addr_expr_1 (tree arg, bool str > return error_mark_node; > } > > + if (TREE_CODE (t) == FUNCTION_DECL > + && DECL_IMMEDIATE_FUNCTION_P (t) > + && cp_unevaluated_operand == 0 > + && (current_function_decl == NULL_TREE > + || !DECL_IMMEDIATE_FUNCTION_P (current_function_decl))) This doesn't cover some of the other cases of immediate context; we should probably factor most of immediate_invocation_p out into a function called something like in_immediate_context and use it here, and in several other places as well. > + { > + if (complain & tf_error) > + error_at (loc, "taking address of an immediate function %qD", > + t); > + return error_mark_node; > + } > + > type = build_ptrmem_type (context_for_name_lookup (t), > TREE_TYPE (t)); > - t = make_ptrmem_cst (type, TREE_OPERAND (arg, 1)); > + t = make_ptrmem_cst (type, t); > return t; > } > > --- gcc/testsuite/g++.dg/cpp2a/consteval20.C.jj 2021-10-15 19:40:38.691900472 +0200 > +++ gcc/testsuite/g++.dg/cpp2a/consteval20.C 2021-10-15 19:49:15.281508419 +0200 > @@ -0,0 +1,24 @@ > +// PR c++/102753 > +// { dg-do compile { target c++20 } } > + > +struct S { > + consteval int foo () const { return 42; } > +}; > + > +constexpr S s; > + > +int > +bar () > +{ > + return (s.*&S::foo) (); // { dg-error "taking address of an immediate function" } > +} > + > +constexpr auto a = &S::foo; // { dg-error "taking address of an immediate function" } > + > +consteval int > +baz () > +{ > + return (s.*&S::foo) (); > +} > + > +static_assert (baz () == 42); > > Jakub >