From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 3400F3857345 for ; Wed, 27 Apr 2022 15:47:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3400F3857345 Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-88-60Jct0uZP-Wv9KLPzuCjmg-1; Wed, 27 Apr 2022 11:47:05 -0400 X-MC-Unique: 60Jct0uZP-Wv9KLPzuCjmg-1 Received: by mail-qt1-f198.google.com with SMTP id 20-20020ac85714000000b002f380aae351so1375027qtw.20 for ; Wed, 27 Apr 2022 08:47:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=JnjrjZeF7EaA1dqG5y26TUjlF1HVIgzonFE6vqLyuK4=; b=FdqQHwyOSMkqmo3EK3pX3vzaIt8zFa3fAKDjCvBOAiFRViCen4HmX/E82oPP8pLXGn V4ljWUlbYtyRPhGETEVWhEafYLIODpdfvUg9Fux6oNXOJZR4F+62GNFqiT+biqYq/pUL C1rPK1aN7YtEjADhLCh72A0/ePrnzDkmQ8hY4UokN/Za5O27HuyJS8kZB+Sg+bPB6b44 RLVlVlcp3RajK3NTeRxHCcZvIRr9cJVJEXRJl1d0iKHRNglQA51zO8V5pnJUPg8d+Gqk j1VaQDU1SnGTKdTf2acMJWUio1rLyXIt30FKZAq2VJc07y7BrlSVQM9ygrBEEPEqgjBm WcxQ== X-Gm-Message-State: AOAM530Vbsc7SBuSLXSfhtmWrD3hXhFryudc8gSfpxtJ4dEHsNulQMsP Y2Pk21B4SpXzCGfGhWoyHvhTBGLB7Gzu6Bi3dmGEYpKe9hIfOHWkl5rgBWGlwfIh6kVxha6Z66o 05bd2gfleV99JhDeruA== X-Received: by 2002:a05:622a:487:b0:2f2:4a6:6a43 with SMTP id p7-20020a05622a048700b002f204a66a43mr19512386qtx.63.1651074424486; Wed, 27 Apr 2022 08:47:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy9+rKKRyKITOZnAVEzcsKJ/vKLC8Vh8hF4S/ccI6gxLf02v8ULb+Iavv0tH53hwOUJ0XrPFQ== X-Received: by 2002:a05:622a:487:b0:2f2:4a6:6a43 with SMTP id p7-20020a05622a048700b002f204a66a43mr19512363qtx.63.1651074424019; Wed, 27 Apr 2022 08:47:04 -0700 (PDT) Received: from [192.168.1.100] (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id o189-20020a375ac6000000b0069f73d3b544sm3023577qkb.43.2022.04.27.08.47.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 27 Apr 2022 08:47:03 -0700 (PDT) Message-ID: Date: Wed, 27 Apr 2022 11:47:02 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.1 Subject: Re: [PATCH] c++: enum in generic lambda at global scope [PR105398] To: Marek Polacek , Patrick Palka Cc: GCC Patches References: <20220426230317.677363-1-polacek@redhat.com> <2b09acb9-7c0b-62bd-2baa-dfcac7f574f6@idea> From: Jason Merrill In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Wed, 27 Apr 2022 15:47:08 -0000 On 4/27/22 08:59, Marek Polacek wrote: > On Wed, Apr 27, 2022 at 08:24:54AM -0400, Patrick Palka wrote: >> On Tue, 26 Apr 2022, Marek Polacek via Gcc-patches wrote: >> >>> We crash compiling this test since r11-7993 which changed >>> lookup_template_class_1 so that we only call tsubst_enum when >>> >>> !uses_template_parms (current_nonlambda_scope ()) >>> >>> But here current_nonlambda_scope () is the global NAMESPACE_DECL ::, which >>> doesn't have a type, therefore is considered type-dependent. So we don't >>> call tsubst_enum, and crash in tsubst_copy/CONST_DECL because we didn't >>> find the e1 enumerator. >>> >>> I don't think any namespace can depend on any template parameter, so >>> this patch tweaks uses_template_parms. >>> >>> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/11? >>> >>> PR c++/105398 >>> >>> gcc/cp/ChangeLog: >>> >>> * pt.cc (uses_template_parms): Return false for any NAMESPACE_DECL. >>> >>> gcc/testsuite/ChangeLog: >>> >>> * g++.dg/cpp1y/lambda-generic-enum2.C: New test. >>> --- >>> gcc/cp/pt.cc | 2 +- >>> gcc/testsuite/g++.dg/cpp1y/lambda-generic-enum2.C | 15 +++++++++++++++ >>> 2 files changed, 16 insertions(+), 1 deletion(-) >>> create mode 100644 gcc/testsuite/g++.dg/cpp1y/lambda-generic-enum2.C >>> >>> diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc >>> index 3cf1d7af8d2..e785c5db142 100644 >>> --- a/gcc/cp/pt.cc >>> +++ b/gcc/cp/pt.cc >>> @@ -10905,7 +10905,7 @@ uses_template_parms (tree t) >>> || uses_template_parms (TREE_CHAIN (t))); >>> else if (TREE_CODE (t) == TYPE_DECL) >>> dependent_p = dependent_type_p (TREE_TYPE (t)); >>> - else if (t == error_mark_node) >>> + else if (t == error_mark_node || TREE_CODE (t) == NAMESPACE_DECL) >> >> LGTM. In passing, perhaps we should move this t == error_mark_node test >> to the beginning of the function alongside the t == NULL_TREE test? > > Thanks, yeah, maybe. I also don't like the separate declaration of > saved_processing_template_decl, the return type, but I've resisted cleaning > that up, otherwise I never know when to stop. But here's a version with more > cleanups: > > diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h > index e9a3d09ac4c..d0ebbb7a196 100644 > --- a/gcc/cp/cp-tree.h > +++ b/gcc/cp/cp-tree.h > @@ -7311,7 +7311,7 @@ extern tree lookup_template_class (tree, tree, tree, tree, > int, tsubst_flags_t); > extern tree lookup_template_function (tree, tree); > extern tree lookup_template_variable (tree, tree); > -extern int uses_template_parms (tree); > +extern bool uses_template_parms (tree); > extern bool uses_template_parms_level (tree, int); > extern bool in_template_function (void); > extern bool need_generic_capture (void); > diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc > index 3cf1d7af8d2..dc5b9938f2c 100644 > --- a/gcc/cp/pt.cc > +++ b/gcc/cp/pt.cc > @@ -10884,35 +10884,30 @@ find_template_parameters (tree t, tree ctx_parms) > > /* Returns true if T depends on any template parameter. */ > > -int > +bool > uses_template_parms (tree t) > { > - if (t == NULL_TREE) > + if (t == NULL_TREE || t == error_mark_node) > return false; > > - bool dependent_p; > - int saved_processing_template_decl; > + /* Namespaces can't depend on any template parameters. */ > + if (TREE_CODE (t) == NAMESPACE_DECL) > + return false; > + > + processing_template_decl_sentinel ptds (/*reset*/false); > + ++processing_template_decl; > > - saved_processing_template_decl = processing_template_decl; > - if (!saved_processing_template_decl) > - processing_template_decl = 1; > if (TYPE_P (t)) > - dependent_p = dependent_type_p (t); > + return dependent_type_p (t); > else if (TREE_CODE (t) == TREE_VEC) > - dependent_p = any_dependent_template_arguments_p (t); > + return any_dependent_template_arguments_p (t); > else if (TREE_CODE (t) == TREE_LIST) > - dependent_p = (uses_template_parms (TREE_VALUE (t)) > - || uses_template_parms (TREE_CHAIN (t))); > + return (uses_template_parms (TREE_VALUE (t)) > + || uses_template_parms (TREE_CHAIN (t))); > else if (TREE_CODE (t) == TYPE_DECL) > - dependent_p = dependent_type_p (TREE_TYPE (t)); > - else if (t == error_mark_node) > - dependent_p = false; > + return dependent_type_p (TREE_TYPE (t)); > else > - dependent_p = instantiation_dependent_expression_p (t); > - > - processing_template_decl = saved_processing_template_decl; > - > - return dependent_p; > + return instantiation_dependent_expression_p (t); > } > > /* Returns true iff we're processing an incompletely instantiated function > > > Maybe go with the original patch for GCC 12 and leave the cleanups for GCC 13? Sounds good to me. Jason