From patchwork Tue Dec 12 18:40:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 81998 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5DF1C3857B9C for ; Tue, 12 Dec 2023 18:41:07 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 8270E3858C2F for ; Tue, 12 Dec 2023 18:40:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8270E3858C2F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8270E3858C2F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702406452; cv=none; b=seKSwQHLC27Z4WncAyh0AlQtKtwTKIjtIge1HHxYFJMMDCqAxpac5CaYzyKxCmZB4Y11D01gHPaRYiFNxP0P4wl4fpfcmrFo4xYcQ8WJMW9+qbKxRI1TOTHDyIhxy4U2z+xc0aZ5aOs1k09WUGlHMVSvQz/vRhnyE2mRF9Iya1E= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702406452; c=relaxed/simple; bh=1wH+fRDvwj6aJbipQKN3BlGvD30jiKrFYSlhzstFtAQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=BFj8ntFglPXd6Gw0KKOG9rG2WfzvmJP/+EEF90Sx8mUj+iX1hG+UAjYM+CafFD0IjFPuqbz3g1tyUj1pmx/1uck0G+NJYgLBWh+UZ2e23sybm8tVDoz7QTDvdjLa56u5cBWmEkUhSlSYmK3bakCuKM6Z2a51NbbqmFXsHp3B8Y0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702406451; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=CHy8L/0FKpXJ9rIMmE1aDh06K5hzPi1CiFi810z7f5k=; b=PuwMjAnJH0cRI4bIA/01D3T0il9EsBtv9MvmLw8JaM5AiTvAETDhL1uSD5iuGe++PiZnq4 cmvy6g34Q/LlKArFXhQx/Ge9n4OQB0DOLP5ihzg8YhUPP2TqfbeXA4E6o1n/Qr/owNKgbJ GjuERlWGJjpFwAgH5vd4GJLP7Wrd1xQ= Received: from mail-oo1-f69.google.com (mail-oo1-f69.google.com [209.85.161.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-683-wdK6-N2yN-eFSuABhG7Tvw-1; Tue, 12 Dec 2023 13:40:49 -0500 X-MC-Unique: wdK6-N2yN-eFSuABhG7Tvw-1 Received: by mail-oo1-f69.google.com with SMTP id 006d021491bc7-58a21120248so6190339eaf.0 for ; Tue, 12 Dec 2023 10:40:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702406448; x=1703011248; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=CHy8L/0FKpXJ9rIMmE1aDh06K5hzPi1CiFi810z7f5k=; b=c8PBHDz/h4GE/x8D5/PYglhF+txabBHCJjuhZsJc2mxnP0nrlsAXQLY8NfAY9RXtk6 icACmQMAnJfv0VUiHgdo8KRyALH7KkN8i3w7ceVK6hGGR+NVCjCx4brF5ItOyrxGmxDr dl3MEk3vxrR8y1dpzt2diTRfoIzOmiTAM5CborpU88357pCyXiQGdzSdoLh5uP3WsR80 f/8vrq7SWBMsSEhTOgb4QmPDL+y0I0BfTh76oofNuR+VisQVtwIhBzRwN07vFbIjh9iW +vLcZ987Faq0SPsrK0/7FFWRHYa8y+OS0vNP6pl60TBv6rX3mSYPUD7kAWbTTyujex3y J/8w== X-Gm-Message-State: AOJu0YxZEkG2fzntPdFMLTo2mYY63aMw/Pxe0U9Ww3Qf9nhuGhf+3LST mdAAnWGHm6+ny7J8zVDvRm6gr0pVLjOVOHw63zFydWbElPHWyW5C44VbEHLSxmBjwy/jE0fvR4z O5n1pZRHCXOTvA0o4MQcMk/e3tXDrib9ktx1Tk3RD56FmTLnPTM8/fakuVfTeRmky1ftT6DPR4j s= X-Received: by 2002:a05:6359:5c02:b0:170:3429:3fc9 with SMTP id pu2-20020a0563595c0200b0017034293fc9mr1676275rwb.46.1702406448089; Tue, 12 Dec 2023 10:40:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IHaFvmf0zQ7U3rs8bVSdQq9JGWqJHGqgi7MaFylDf/n3ArMAYzhVvSnZtxtvYqFZZfSBThtgA== X-Received: by 2002:a05:6359:5c02:b0:170:3429:3fc9 with SMTP id pu2-20020a0563595c0200b0017034293fc9mr1676267rwb.46.1702406447677; Tue, 12 Dec 2023 10:40:47 -0800 (PST) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id um14-20020a05620a6d8e00b007770673e757sm3920442qkn.94.2023.12.12.10.40.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 10:40:47 -0800 (PST) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: unifying FUNCTION_DECLs [PR93740] Date: Tue, 12 Dec 2023 13:40:37 -0500 Message-ID: <20231212184037.3040106-1-ppalka@redhat.com> X-Mailer: git-send-email 2.43.0.76.g1a87c842ec MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? I considered removing the is_overloaded_fn test now as well, but it could in theory be hit (and not subsumed by the type_unknown_p test) for e.g. OVERLOAD of a single FUNCTION_DECL. I wonder if that's something we'd see here? If not, I can remove the test. It seems safe to remove as far as the testsuite is concerned. -- >8 -- unify currently always returns success when unifying two FUNCTION_DECLs (due to the is_overloaded_fn deferment within the default case), which means for the below testcase unify incorrectly matches &A::foo with &A::bar, which leads to deduction failure for the index_of calls due to a bogus base class ambiguity. This patch makes us instead handle unification of FUNCTION_DECL like other decls, i.e. according to their identity. PR c++/93740 gcc/cp/ChangeLog: * pt.cc (unify) : Handle it like FIELD_DECL and TEMPLATE_DECL. gcc/testsuite/ChangeLog: * g++.dg/template/ptrmem34.C: New test. --- gcc/cp/pt.cc | 1 + gcc/testsuite/g++.dg/template/ptrmem34.C | 27 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 gcc/testsuite/g++.dg/template/ptrmem34.C diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index c2ddbff405b..a8966e223f1 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -24967,6 +24967,7 @@ unify (tree tparms, tree targs, tree parm, tree arg, int strict, gcc_unreachable (); case FIELD_DECL: + case FUNCTION_DECL: case TEMPLATE_DECL: /* Matched cases are handled by the ARG == PARM test above. */ return unify_template_argument_mismatch (explain_p, parm, arg); diff --git a/gcc/testsuite/g++.dg/template/ptrmem34.C b/gcc/testsuite/g++.dg/template/ptrmem34.C new file mode 100644 index 00000000000..c349ca55639 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/ptrmem34.C @@ -0,0 +1,27 @@ +// PR c++/93740 +// { dg-do compile { target c++11 } } + +struct A { + void foo(); + void bar(); +}; + +template +struct const_val{}; + +template +struct indexed_elem{}; + +using mem_fun_A_foo = const_val; +using mem_fun_A_bar = const_val; + +struct A_indexed_member_funcs + : indexed_elem<0, mem_fun_A_foo>, + indexed_elem<1, mem_fun_A_bar> +{}; + +template +constexpr int index_of(indexed_elem) { return N; } + +static_assert(index_of(A_indexed_member_funcs{}) == 0, ""); +static_assert(index_of(A_indexed_member_funcs{}) == 1, "");