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 7481B3858D39 for ; Mon, 3 Apr 2023 20:19:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7481B3858D39 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=1680553145; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2DPA8CSU1ZiIZQoz28QmzTbDLObNBBWK7+cCwsxqKrQ=; b=H9BDA+87QmJJIGO/h6Ru58Oigs2WkB1QRHuyirvkM69E7iC/0WYWLSWX0alCERVD2eu64s YwKRGTIrr5R0ebXzyZrXYL3dYrDTn2u+d2gY0+9ZoeSOPTTVvtN4D3Tc9RjURdKWCc24xC NyiNh6IXiy+lCZ9PYR5bgM/9hAsuXFU= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-198-_untSxf_P76yZdro1pAyng-1; Mon, 03 Apr 2023 16:19:03 -0400 X-MC-Unique: _untSxf_P76yZdro1pAyng-1 Received: by mail-qk1-f200.google.com with SMTP id 203-20020a370ad4000000b00746981f8f4bso13765086qkk.13 for ; Mon, 03 Apr 2023 13:19:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680553143; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=2DPA8CSU1ZiIZQoz28QmzTbDLObNBBWK7+cCwsxqKrQ=; b=RNTpsQHQpEHN67I7vNeQ8no4aEjxu9zI57elRu8G3zYChtcrnp34bYxkrbtPjifAmB F02PGXg1bEMbe3SDyB+Y9+CRLtf3ouGAHZ2gEtiEIc056lcKdx+R9jpKjGFaDwtRlUj3 SMArb8T9kC35tHZUAdNBuKLzMfshAnUXJEpYStYmqr+HFdMu6WRHJKOS35w0SOORV2f5 /2nGJA9UReJfAor9bJWxl71Rj017S6i8zyqZZMcfFdAw84VJ7mPvy8LaW+dn6Vwfofcj swp6uDzTH9aN0Tg/V2X4JDXv/jeIlpXkW5M5+h1CvW9SrkuC4zqMraYTncDEvPnicoIr n60Q== X-Gm-Message-State: AO0yUKV375WULoHB2n0Fx1cWFuVfL3UaUoPmKtFSF9b6K4tc0oYNtHMg KxLR3s3k/HONzaf4BqrCLuFkeeCvDouIXN4yPben+ljq2oKkSfsiqG2Oq0vyQ2ZWlkS1PPsuZw1 gPPhIF9f1cXku1ysLKs2ECU3J2g== X-Received: by 2002:a05:622a:1491:b0:3a7:e9a2:4f4a with SMTP id t17-20020a05622a149100b003a7e9a24f4amr63941324qtx.8.1680553142658; Mon, 03 Apr 2023 13:19:02 -0700 (PDT) X-Google-Smtp-Source: AK7set93lBdMFCyfi3RhWKWrgXm4BtieyGsbk43ga8/Ri8tbo5PzmVY5tPVl6xkOqDWGoVd69P1kog== X-Received: by 2002:a05:622a:1491:b0:3a7:e9a2:4f4a with SMTP id t17-20020a05622a149100b003a7e9a24f4amr63941293qtx.8.1680553142263; Mon, 03 Apr 2023 13:19:02 -0700 (PDT) Received: from [192.168.1.108] (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id r19-20020ae9d613000000b007464fcca543sm3043215qkk.50.2023.04.03.13.19.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 03 Apr 2023 13:19:01 -0700 (PDT) Message-ID: Date: Mon, 3 Apr 2023 16:19:00 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.1 Subject: Re: [PATCH] c++: ICE on loopy var tmpl auto deduction [PR109300] To: Patrick Palka Cc: gcc-patches@gcc.gnu.org References: <20230328173732.1722425-1-ppalka@redhat.com> <4329ac60-d2cf-4014-503d-9c6bf0cea723@idea> From: Jason Merrill In-Reply-To: <4329ac60-d2cf-4014-503d-9c6bf0cea723@idea> 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.2 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_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 4/3/23 12:28, Patrick Palka wrote: > 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 "" } > ^ Yeah, let's just go with your patch, thanks. >> >>> + 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 "" } >> >> >