From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 D72513937432 for ; Tue, 17 Mar 2020 19:55:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D72513937432 Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-22-FGi3DVSMMty-deDXhzzlaA-1; Tue, 17 Mar 2020 15:55:03 -0400 X-MC-Unique: FGi3DVSMMty-deDXhzzlaA-1 Received: by mail-qt1-f200.google.com with SMTP id d2so22446660qtr.9 for ; Tue, 17 Mar 2020 12:55:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=ZhlxGfmoFsbNJYXugBvUFEfvVdEDwZek/zTTsyuyoTU=; b=BmYZQfHmvjmvLgYV6Ala4rHVEWWGRIw4m0bJ870WM3IIToG3XuwZA3hNtfhZ1rc7Eu 8H1jIuIFsB3Y8KPv7X4E09oXNNh0AZqaNHsDpHE1nuSbDYuEHkJofVIb3qLUE+27Nojl ZifFargRnSmjPuQ3prP6pikZNrYScV7uD8x0gmRYXs1Sl4MxiX8gn98NXl9JZnu2vphi +VA3KJR3J8Cn+WITFBHC56h7ofQmHmmzr28KZoGwMovH55mLvd8/XTKlY83vQs7LR2sO tn7NGLfbS6bL79gnCnvCV8H+FB1tpSnTWKZ4H3GmFOY3Tc49WJaEomnxUUGptzSiaRvd WGTA== X-Gm-Message-State: ANhLgQ12Ur1G3kwZYcalH8fsWufdIBae42Iti5JHRGvVUjQwu9t6kwje gAlXPEBuSQhwPgGnu57teh9SSiT1JVZujTGJDoCRJgusrhG+630/Vy/6xLI+9+BArfHxbZmUy9E 7l7s9SjfnQRoHi7WYZg== X-Received: by 2002:a37:3c9:: with SMTP id 192mr599040qkd.330.1584474900941; Tue, 17 Mar 2020 12:55:00 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtRRDQVl3jnGinc9SOoZvYLZjx/j1plRlQ9ET74xAC39l/ZWSWpXdtUX15/n1LtI7q4HTGpcg== X-Received: by 2002:a37:3c9:: with SMTP id 192mr599016qkd.330.1584474900600; Tue, 17 Mar 2020 12:55:00 -0700 (PDT) Received: from [192.168.1.148] (209-6-216-142.s141.c3-0.smr-cbr1.sbo-smr.ma.cable.rcncustomer.com. [209.6.216.142]) by smtp.gmail.com with ESMTPSA id y127sm2601265qkb.76.2020.03.17.12.54.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 17 Mar 2020 12:54:59 -0700 (PDT) Subject: Re: [PATCH] c++: Diagnose a deduction guide in a wrong scope [PR91759] To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org References: <20200317084902.GX2156@tucnak> From: Jason Merrill Message-ID: <10abd205-1301-d32f-ad47-8d2c6b5d8d34@redhat.com> Date: Tue, 17 Mar 2020 15:54:57 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.3.0 MIME-Version: 1.0 In-Reply-To: <20200317084902.GX2156@tucnak> Content-Language: en-US X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit 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-List-Received-Date: Tue, 17 Mar 2020 19:55:05 -0000 On 3/17/20 4:49 AM, Jakub Jelinek wrote: > 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? How about always diagnosing this here, and moving the deduction guide code in grokfndecl up above set_decl_namespace to avoid a duplicate diagnostic? > 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. > > --- 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" } > > Jakub >