From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 34356 invoked by alias); 4 Feb 2016 16:57:38 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 34343 invoked by uid 89); 4 Feb 2016 16:57:37 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 04 Feb 2016 16:57:36 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id CEF07263C; Thu, 4 Feb 2016 16:57:34 +0000 (UTC) Received: from [10.10.116.37] (ovpn-116-37.rdu2.redhat.com [10.10.116.37]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u14GvY1h024670; Thu, 4 Feb 2016 11:57:34 -0500 Subject: Re: [PATCH] Fix constexpr evaluation of comparisons involving pointer-to-members To: Patrick Palka References: <1450739227-18825-1-git-send-email-patrick@parcs.ath.cx> <56B0FAA2.3080804@redhat.com> <56B35F0A.5090008@redhat.com> Cc: GCC Patches From: Jason Merrill Message-ID: <56B382FE.2030904@redhat.com> Date: Thu, 04 Feb 2016 16:57:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2016-02/txt/msg00333.txt.bz2 On 02/04/2016 10:32 AM, Patrick Palka wrote: > On Thu, Feb 4, 2016 at 9:24 AM, Jason Merrill wrote: >> On 02/03/2016 12:51 PM, Patrick Palka wrote: >>> >>> + && (integer_minus_onep (lhs) >>> + || integer_minus_onep (rhs))) >> >> >> Let's use null_member_pointer_value_p here. > > Done. > >> >> Please add pointers to member functions to the testcase. > > This does not currently work properly because comparisons between > distinct pointers to (non-virtual) member functions eventually perform > a comparison between two distinct FUNCTION_DECLs, and fold_binary_loc > currently does not fold away such comparisons. So any static_asserts > that perform comparisons between distinct function pointers or between > distinct pointers to (non-virtual) member functions fail with > "non-constant condition for static assertion". (Comparisons between > pointers to distinct virtual member functions _do_ work because in > that case we are ultimately just comparing integer offsets, not > FUNCTION_DECLs. And comparisons between equivalent pointers trivially > work.) > > I think the problem may lie in symtab_node::equal_address_to, which > apparently returns -1, instead of 0, for two obviously distinct > FUNCTION_DECLs. Right, because they might be defined as aliases elsewhere. But it looks like it should work if you define f and g. > Test case: > > #define SA(x) static_assert ((x), #x) > > void f (); > void g (); > > struct X { void f (); void g (); }; > > void > foo () > { > SA (&f != &g); // "non-constant expression" > SA (&X::f != &X::g); // "non-constant expression" > } >