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 674CA3858D39 for ; Mon, 3 Apr 2023 16:28:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 674CA3858D39 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680539317; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=A4S3N2vm5dT+epRGNzOIq4qUYGszTJZRXbnsD6QCAbk=; b=SBlette4Ie4lTyMHZVETwdaB0l+9ackExSoJZEakZJSmZWuh/MC9roERPHq9aD2cUiNjPa hfxCDvz3Iuh0Ka/U+T8lQkoHVwy1lF43GKms4W7U0b1pmQWZKyGfPHszEPUOrVBRdgi+WX bT3tciCY60dNOC0M2HKymUIW1F3wtaQ= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-280-_snfiiVoO1eBTj31WQnkcg-1; Mon, 03 Apr 2023 12:28:34 -0400 X-MC-Unique: _snfiiVoO1eBTj31WQnkcg-1 Received: by mail-qv1-f72.google.com with SMTP id r4-20020ad44044000000b005ad0ce58902so13236633qvp.5 for ; Mon, 03 Apr 2023 09:28:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680539314; h=mime-version:references:message-id:in-reply-to:subject:cc:to:date :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=A4S3N2vm5dT+epRGNzOIq4qUYGszTJZRXbnsD6QCAbk=; b=mJ0a8C+V4s8qzyytuf8JZi/iV4AxlvmAjH3OREbPoM2kbQlvVv1tFNyZZAoonnhM/p R/kE9qzvLlgZQ24mIHjCES/+Bsh8tc82eiqZP3J0pxuApn9IghLi0zMWWsrzJf1nAEyj sJ6rPKsOwTAUg7q+z/T0KeBn/k4Q+NRldrlrETwbssHWOGZI6vHun0uV/8LEEusizs04 8zfbBWg/e89OAp2XoRKFBlUo4dh4xXZ8Q5DXpLFFOdCK/o8N06x2iVnlsNO0N9Axzi+M 2J7KxU8jmH/7rCjRftK74gYjroigXUYH4Q+RV/44+ERABrJhbQ5DV8mSiFL5lWFNrG1f pUgA== X-Gm-Message-State: AAQBX9d2Qawvy/MkitKBa8hup+DhtWlAq/M49GavEN5ZvtxOSuyNwHuL h1ton2I9EMjKTqO7sgBOe5ERPL+SLzAQuvQguIjugkitJXSweRAsjNOSp/OSuYMA05OUKTYM0YW Dbeycwc3+Hly4PVlCjA== X-Received: by 2002:ad4:594d:0:b0:5a4:548e:4ed6 with SMTP id eo13-20020ad4594d000000b005a4548e4ed6mr59061207qvb.40.1680539313870; Mon, 03 Apr 2023 09:28:33 -0700 (PDT) X-Google-Smtp-Source: AKy350aPQQNcCd0d7Vj2RhpIV2D0UQ7Y9+ALi3zTLJEaLHTyyuw7X3KgRnkKb/XBN+ZCfG4xipmQqQ== X-Received: by 2002:ad4:594d:0:b0:5a4:548e:4ed6 with SMTP id eo13-20020ad4594d000000b005a4548e4ed6mr59061179qvb.40.1680539313554; Mon, 03 Apr 2023 09:28:33 -0700 (PDT) Received: from [192.168.1.130] (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id qf11-20020a0562144b8b00b005e3bda8a5e0sm1308520qvb.6.2023.04.03.09.28.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Apr 2023 09:28:33 -0700 (PDT) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Mon, 3 Apr 2023 12:28:32 -0400 (EDT) To: Jason Merrill cc: Patrick Palka , gcc-patches@gcc.gnu.org Subject: Re: [PATCH] c++: ICE on loopy var tmpl auto deduction [PR109300] In-Reply-To: Message-ID: <4329ac60-d2cf-4014-503d-9c6bf0cea723@idea> References: <20230328173732.1722425-1-ppalka@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-13.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_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Wed, 29 Mar 2023, Jason Merrill wrote: > On 3/28/23 13:37, Patrick Palka wrote: > > Now that we resolve non-dependent variable template-ids ahead of time, > > cp_finish_decl needs to handle a new invalid situation: we can end up > > trying to instantiate a variable template with deduced return type > > before we fully parsed (and attached) its initializer. > > > > Bootstrapped and regtested on x86_64-pc-linux-gnu, does this OK for > > trunK? > > > > PR c++/109300 > > > > gcc/cp/ChangeLog: > > > > * decl.cc (cp_finish_decl): Diagnose ordinary auto deduction > > with no initializer instead of asserting. > > > > gcc/testsuite/ChangeLog: > > > > * g++.dg/cpp1y/var-templ79.C: New test. > > --- > > gcc/cp/decl.cc | 15 ++++++++++++++- > > gcc/testsuite/g++.dg/cpp1y/var-templ79.C | 5 +++++ > > 2 files changed, 19 insertions(+), 1 deletion(-) > > create mode 100644 gcc/testsuite/g++.dg/cpp1y/var-templ79.C > > > > diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc > > index 20b980f68c8..2c91693b99d 100644 > > --- a/gcc/cp/decl.cc > > +++ b/gcc/cp/decl.cc > > @@ -8276,7 +8276,20 @@ cp_finish_decl (tree decl, tree init, bool > > init_const_expr_p, > > return; > > } > > - gcc_assert (CLASS_PLACEHOLDER_TEMPLATE (auto_node)); > > + if (CLASS_PLACEHOLDER_TEMPLATE (auto_node)) > > + /* Class deduction with no initializer is OK. */; > > + else > > + { > > + /* Ordinary auto deduction without an initializer, a situation > > + which grokdeclarator already catches and rejects for the most > > + part. But we can still get here if we're instantiating a > > + variable template before we've fully parsed (and attached) > > its > > + initializer, e.g. template auto x = x; */ > > In the case of recursively dependent instantiation I'd hope to have an > error_mark_node initializer, rather than none? Do you mean setting the initializer to error_mark_node after the fact, e.g. @@ -8288,7 +8297,7 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, error_at (DECL_SOURCE_LOCATION (decl), "declaration of %q#D has no initializer", decl); TREE_TYPE (decl) = error_mark_node; - return; + init = error_mark_node; } } d_init = init; or before the fact, i.e. setting DECL_INITIAL to error_mark_node as a sentinel value for detecting recursion before we begin parsing a variable initializer? The former should work I suppose, but the latter is problematic because we also call cp_finish_decl with init=error_mark_node when the initializer is generally invalid, so by overloading the meaning of error_mark_node here and checking for it from cp_finish_decl we would end up emitting a bogus extra diagnostic in a bunch of cases e.g. g++.dg/pr53055.C: int i = p ->* p ; // invalid initializer I guess we would need to use a different sentinel value for detecting recursion, or expose and inspect the 'lambda_scope' stack which already keeps track of whether we're in the middle of a variable initializer... Dunno if it's worth it just for sake of a better diagnostic for this corner case, I notice e.g. Clang doesn't give a great diagnostic either: src/gcc/testsuite/g++.dg/cpp1y/var-templ79.C:5:6: error: declaration of variable 'x' with deduced type 'auto' requires an initializer auto x = x; // { dg-error "" } ^ > > > + error_at (DECL_SOURCE_LOCATION (decl), > > + "declaration of %q#D has no initializer", decl); > > + TREE_TYPE (decl) = error_mark_node; > > + return; > > + } > > } > > d_init = init; > > if (d_init) > > diff --git a/gcc/testsuite/g++.dg/cpp1y/var-templ79.C > > b/gcc/testsuite/g++.dg/cpp1y/var-templ79.C > > new file mode 100644 > > index 00000000000..3c0d276153a > > --- /dev/null > > +++ b/gcc/testsuite/g++.dg/cpp1y/var-templ79.C > > @@ -0,0 +1,5 @@ > > +// PR c++/109300 > > +// { dg-do compile { target c++14 } } > > + > > +template > > +auto x = x; // { dg-error "" } > >