From patchwork Mon Jul 20 20:18:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1332630 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=O64A0MQv; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4B9Y2r4tSPz9sR4 for ; Tue, 21 Jul 2020 06:18:43 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 138C93857C7B; Mon, 20 Jul 2020 20:18:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 138C93857C7B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1595276321; bh=KlrH+CWTH6l0ZCIojq4nJUwG/S+/g8OYdESVRAs5sVI=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=O64A0MQv6ob0xPRlKSmX6OjncZFb/ivMJS0lp8J9+C/hNezYD63YNCRYQnKCRqy3g fZ5Ine1xkZ9NXhT8wicXJrhJxw+WnZAfCH4Gwq7/v6jX3ZFH/2Rhhs/8UOpKYcteVR cVrEQd5Clo0Ghi5rZjqPihgM0tqHsYWLwodU7Gw4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by sourceware.org (Postfix) with ESMTP id 70F093857C51 for ; Mon, 20 Jul 2020 20:18:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 70F093857C51 Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-263-Rwmg03koNrmDR3af16W_kA-1; Mon, 20 Jul 2020 16:18:36 -0400 X-MC-Unique: Rwmg03koNrmDR3af16W_kA-1 Received: by mail-qt1-f199.google.com with SMTP id w15so878919qti.21 for ; Mon, 20 Jul 2020 13:18:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=KlrH+CWTH6l0ZCIojq4nJUwG/S+/g8OYdESVRAs5sVI=; b=dbnvVhdRoAFUCZK6qeXM4t3mQIc0DxzpDCSQ6/mt2JxY/yNrvQsfs/yRZKPTOJTC5Z rhSIsvJ63d+pVbhTuyfupLyrBJ3VOlWgPyj1Uyj9o9nuSzBrghpj6xLD2JwrgHbDWmeu wkyMPKDy5G818wWe45K6LpoGDaITfvx+ZsFMWBovbJJEmOughcPNNeSTqUp08dAwOlzT +TXcjSCAF2lWqZo2R+X0qbOcgeGBc72O6Xp0pP8RN5DjDqxZltbNkyh7QVchrrvmXqkh EXGzCxTA/1inhu/m27V7LF7rUDugT0tXNyjBMF6EzwB9eShxYM8uI6+vjL4AgxCHS5ue 1+AA== X-Gm-Message-State: AOAM5302jc5vituwo9tdgKSBCUfvP0G8VOGsLAEd3XEpmnue9zYXWmg6 cXmwoKrdZaX7UgruLwxGAi/xIMBoh5Bfsfy3YQaeqnt8nFOl6ICM6DUzvmI31RZ2oBRYzzz68lx kDOksdjQLqyvuFYrgjA== X-Received: by 2002:a05:6214:72c:: with SMTP id c12mr22788966qvz.76.1595276315350; Mon, 20 Jul 2020 13:18:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwN6x9OCkhCLfDiNlhCnKu6UdsKf5w2BWpliwTJO2aiILwY6gFF4wSk/fx+NHGgQtg17BXnFw== X-Received: by 2002:a05:6214:72c:: with SMTP id c12mr22788947qvz.76.1595276315121; Mon, 20 Jul 2020 13:18:35 -0700 (PDT) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id p53sm22075501qtc.85.2020.07.20.13.18.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jul 2020 13:18:34 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: abbreviated function template friend matching [PR96106] Date: Mon, 20 Jul 2020 16:18:31 -0400 Message-Id: <20200720201831.3759722-1-ppalka@redhat.com> X-Mailer: git-send-email 2.28.0.rc1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-16.9 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_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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-Patchwork-Original-From: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" In the below testcase, duplicate_decls wasn't merging the tsubsted friend declaration for 'void add(auto)' with its definition, because reduce_template_parm_level (during tsubst_friend_function) lost the DECL_VIRTUAL_P flag on the invented 'auto' template parameter, which made template_heads_equivalent_p deem the two template heads as not equivalent in C++20 mode. This patch makes reduce_template_parm_level carry over the DECL_VIRTUAL_P from the original TEMPLATE_PARM_DECL. Passes 'make check-c++' and the cmcstl2 testsuite. Does this look OK for trunk after a full bootstrap and regtest? gcc/cp/ChangeLog: PR c++/96106 * pt.c (reduce_template_parm_level): Carry over DECL_VIRTUAL_P from the original TEMPLATE_PARM_DECL. gcc/testsuite/ChangeLog: PR c++/96106 * g++.dg/concepts/abbrev7.C: New test. --- gcc/cp/pt.c | 1 + gcc/testsuite/g++.dg/concepts/abbrev7.C | 14 ++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 gcc/testsuite/g++.dg/concepts/abbrev7.C diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index defc2a9abd8..3f7b89141b6 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -4453,6 +4453,7 @@ reduce_template_parm_level (tree index, tree type, int levels, tree args, type); TREE_CONSTANT (decl) = TREE_CONSTANT (orig_decl); TREE_READONLY (decl) = TREE_READONLY (orig_decl); + DECL_VIRTUAL_P (decl) = DECL_VIRTUAL_P (orig_decl); DECL_ARTIFICIAL (decl) = 1; SET_DECL_TEMPLATE_PARM_P (decl); diff --git a/gcc/testsuite/g++.dg/concepts/abbrev7.C b/gcc/testsuite/g++.dg/concepts/abbrev7.C new file mode 100644 index 00000000000..443c1b7871b --- /dev/null +++ b/gcc/testsuite/g++.dg/concepts/abbrev7.C @@ -0,0 +1,14 @@ +// PR c++/96106 +// { dg-do compile { target concepts } } + +template +struct number { + friend void add(auto); +}; + +void add(auto) { } + +void foo() { + number n; + add(n); // { dg-bogus "ambiguous" } +}