From patchwork Fri Nov 16 22:32:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Oliva X-Patchwork-Id: 999192 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-490344-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="XxMzdWYv"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42xY1c0FNHz9s9h for ; Sat, 17 Nov 2018 09:34:11 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=cUCDrkVjUc+hR9H/ mVntEubQ+hqgP/DTNV3G2dse8GLHSRiKHJwxM668b6Lp20Z24X/LBqrXkSRWIfeB mtbM16yJEEGScXBRbj9a9T/zQdg62RPOJCua6viPPJ86PgmXuLlR7V5Hypzx9PM7 n6RxZrmgIRyH7pxclTLvZfzoyOY= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=u6HWXk3CAUwmZqC0ApUH6W nfC+g=; b=XxMzdWYvC2oxp4K6pcDtgeNDpnQS3YhppQ1aQ3c4LLX1IDiIEHNk4y 5GOyJXZTFUY40R8Y8QKFF9zgCZK+UM/ZjzBTMEaIWRpq5ERDQ1vzmrwqEs7y0Q/0 HStZaA5D1BcCmh4MM3tkZX0rwJQwO8H2StReClkym0cLlxcvKpnBA= Received: (qmail 110822 invoked by alias); 16 Nov 2018 22:33:33 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 109478 invoked by uid 89); 16 Nov 2018 22:33:09 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Enter, Hx-languages-length:2244, tsubsting, sk:tsubst_ 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 ESMTP; Fri, 16 Nov 2018 22:33:07 +0000 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7580730820F0; Fri, 16 Nov 2018 22:33:06 +0000 (UTC) Received: from free.home (ovpn04.gateway.prod.ext.phx2.redhat.com [10.5.9.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F1F5660FCE; Fri, 16 Nov 2018 22:33:05 +0000 (UTC) Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTP id wAGMWnYC739217; Fri, 16 Nov 2018 20:32:49 -0200 From: Alexandre Oliva To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, nathan@acm.org Subject: [PATCH] [PR86747] tsubst friend tpl ctxt before looking it up for dupes Date: Fri, 16 Nov 2018 20:32:49 -0200 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 When a member template is redeclared as a friend, we enter the context of the member before looking it up, and then we check that the decls are compatible. However, when the member template references template types of the enclosing context, say an enclosing template class, the compare fails because the friend decl is already tsubsted, whereas the looked up name isn't. The problem is that the enclosing context is taken from the friend declaration before tsubsting it, so we look up in the context of the generic template instead of that of the tsubsted one we're specializing. The solution is to tsubst the enclosing context when it's a non-namespace scope. Regstrapped on i686- and x86_64-linux-gnu. Ok to install? for gcc/cp/ChangeLog PR c++/86747 * pt.c (tsubst_friend_class): Enter tsubsted class context. for gcc/testsuite/ChangeLog PR c++/86747 * g++.dg/pr86747.C: New. --- gcc/cp/pt.c | 5 ++++- gcc/testsuite/g++.dg/pr86747.C | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/pr86747.C diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 83d0a74b209f..82c8019431b8 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -10568,7 +10568,10 @@ tsubst_friend_class (tree friend_tmpl, tree args) if (TREE_CODE (context) == NAMESPACE_DECL) push_nested_namespace (context); else - push_nested_class (context); + { + context = tsubst (context, args, tf_error, NULL_TREE); + push_nested_class (context); + } tmpl = lookup_name_real (DECL_NAME (friend_tmpl), /*prefer_type=*/false, /*non_class=*/false, /*block_p=*/false, diff --git a/gcc/testsuite/g++.dg/pr86747.C b/gcc/testsuite/g++.dg/pr86747.C new file mode 100644 index 000000000000..5b0a0bb95146 --- /dev/null +++ b/gcc/testsuite/g++.dg/pr86747.C @@ -0,0 +1,8 @@ +// { dg-do compile } + +template class A { + template class C; // #1 + template friend class C; // #2 +}; + +A a;