From patchwork Tue Mar 17 08:49:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 1256114 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=ObIq+Qtg; 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 48hRfx0z6hz9sRR for ; Tue, 17 Mar 2020 19:49:13 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E020438A1033; Tue, 17 Mar 2020 08:49:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E020438A1033 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1584434950; bh=SANkhAhLfjA2rzT4IkjWndIByVJCVRUdrf2+TTzERdA=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=ObIq+Qtgsc5hIVjygDYwGLS6DTenay3V5ql9nCqUuBLsWwDsPDhCFqCuYS8I4fU44 XbvLL8JlBHXxrrAwwBy1n2FituPvmxUkB8Y9oA9TzmHYUQ1Ndr8e2NknC4SXy62EWY ss89bJr7Cihvu6V1TQsPUq/2rqiWekl1+ZyNvjFM= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [63.128.21.74]) by sourceware.org (Postfix) with ESMTP id 68D6C38A1033 for ; Tue, 17 Mar 2020 08:49:08 +0000 (GMT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-414-0tgHDiX2NAWUzlH5SpxnJA-1; Tue, 17 Mar 2020 04:49:06 -0400 X-MC-Unique: 0tgHDiX2NAWUzlH5SpxnJA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 47C8218AB2C8 for ; Tue, 17 Mar 2020 08:49:05 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-112-22.ams2.redhat.com [10.36.112.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CEB6C89E76; Tue, 17 Mar 2020 08:49:04 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id 02H8n2Kv004265; Tue, 17 Mar 2020 09:49:03 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id 02H8n2QE004264; Tue, 17 Mar 2020 09:49:02 +0100 Date: Tue, 17 Mar 2020 09:49:02 +0100 To: Jason Merrill Subject: [PATCH] c++: Diagnose a deduction guide in a wrong scope [PR91759] Message-ID: <20200317084902.GX2156@tucnak> MIME-Version: 1.0 User-Agent: Mutt/1.11.3 (2019-02-01) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-10.2 required=5.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS 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: Jakub Jelinek via Gcc-patches From: "Li, Pan2 via Gcc-patches" Reply-To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi! The following testcase is accepts-invalid since r7-6608-ga56c0ac08242269b. Before that change we had this "deduction guide %qD must be declared in the same scope as %qT" diagnostics for it, after the change it is expected to be diagnosed in set_decl_namespace at the not_found: label in there. On this testcase nothing is diagnosed though, because set_decl_namespace isn't called at all, as in_namespace is NULL. The following patch restores the old warning but does it only in case we don't call set_decl_namespace. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? Or do you prefer something different? 2020-03-17 Jakub Jelinek PR c++/91759 * decl.c (grokfndecl): Restore old diagnostics about deduction guide declared in different scope if in_namespace is NULL_TREE. * g++.dg/cpp1z/class-deduction72.C: New test. Jakub --- gcc/cp/decl.c.jj 2020-03-12 08:26:23.000000000 +0100 +++ gcc/cp/decl.c 2020-03-16 16:25:02.142867924 +0100 @@ -9644,6 +9644,15 @@ grokfndecl (tree ctype, "namespace scope", decl); return NULL_TREE; } + tree type = TREE_TYPE (DECL_NAME (decl)); + if (in_namespace == NULL_TREE + && CP_DECL_CONTEXT (decl) != CP_TYPE_CONTEXT (type)) + { + error_at (location, "deduction guide %qD must be declared in the " + "same scope as %qT", decl, type); + inform (location_of (type), " declared here"); + return NULL_TREE; + } if (funcdef_flag) error_at (location, "deduction guide %qD must not have a function body", decl); --- gcc/testsuite/g++.dg/cpp1z/class-deduction72.C.jj 2020-03-16 16:27:03.997068510 +0100 +++ gcc/testsuite/g++.dg/cpp1z/class-deduction72.C 2020-03-16 16:28:21.241927835 +0100 @@ -0,0 +1,11 @@ +// PR c++/91759 +// { dg-do compile { target c++17 } } + +namespace N { + template + struct X{ X(int); }; // { dg-message "declared here" } +} + +using N::X; + +X(int) -> X; // { dg-error "must be declared in the same scope as" }