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.129.124]) by sourceware.org (Postfix) with ESMTPS id E24373858412 for ; Mon, 24 Oct 2022 14:31:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E24373858412 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=1666621914; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=p+PN7FZOp321WYqQU3wB8FY0v3o1KdXzAQxshH9LGTU=; b=QBNxwUcQCCsefIevYS+HuwF/s815qWvV9myMPCmwqF1vp6DVzdYZa48PN/9y/FVVGjNKIb tc3fHIRjxjjLum3veQ6EbHOJVdYkEe1etvOOLZUfAiJSzsTAuyp/iuBqcOSJNcztGDwYnL r6jJS35maVIqP6lpXBSLdAHtuU3coEI= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-249-s6UiT3TTMrmVHTgvtraRUA-1; Mon, 24 Oct 2022 10:31:53 -0400 X-MC-Unique: s6UiT3TTMrmVHTgvtraRUA-1 Received: by mail-qv1-f70.google.com with SMTP id jn13-20020ad45ded000000b004b1d055fbc7so5282482qvb.2 for ; Mon, 24 Oct 2022 07:31:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references: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=p+PN7FZOp321WYqQU3wB8FY0v3o1KdXzAQxshH9LGTU=; b=fn3tVTy6t0rNc4Sl87bWdvm0C94bMYqDtvaXmb+ETFPjC8VkSb1f/aJRq2idU8pqQw BqZ3OGYlLxEHKWNHNS4WwYFaTvVWindrT3wpyxfNLEzCPEUiDlN4MNw2GrNeGilUZoBs y6C/phQjLqZOTbMrypjxVXMEzMq/iLm7OCmHxJgJCwuYSEqlw+8paFNNFWJNUfUw4WHl P3r/qwdyCaOHONQNyzijjLI2GIxXVQ1P7F0h7jw6tecxcllhx+VTJp2JVa5LC7vQSIB/ V8M4FWx0t6XfvL3NBy9/eG+c/i3VlU+cqUJ7f99SKeUtkd8+PwXAGfAl2eUxPYqzNRAx 73tg== X-Gm-Message-State: ACrzQf1AC0exk69jhoeNuMSrV20MDZKEELWyAwoTfMAcPkO8Y9Qs+qzj PDCNQS4p2gCFT4pB8jgdSP2UGcbxT2I5+CR8CSSjWtt2Jp6Z8BWW1Q0NkKvvajYBKpYSSm3FMPf h0wuJ6Hu17cl3IwHPoA== X-Received: by 2002:a05:6214:2502:b0:4b1:70e4:2653 with SMTP id gf2-20020a056214250200b004b170e42653mr27020955qvb.6.1666621912515; Mon, 24 Oct 2022 07:31:52 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6o0xk3dxy4e4zr2HGL5UUn6FBsWGDMQm8WG2cJf8jIlacC32fmgf5cNZywtGPKmiPVO5G5Zw== X-Received: by 2002:a05:6214:2502:b0:4b1:70e4:2653 with SMTP id gf2-20020a056214250200b004b170e42653mr27020934qvb.6.1666621912195; Mon, 24 Oct 2022 07:31:52 -0700 (PDT) Received: from [192.168.1.101] (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 d20-20020ac851d4000000b0035bafecff78sm12205qtn.74.2022.10.24.07.31.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 24 Oct 2022 07:31:51 -0700 (PDT) Message-ID: Date: Mon, 24 Oct 2022 10:31:50 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.0 Subject: Re: [PATCH] c++: ICE with invalid structured bindings [PR107276] To: Marek Polacek , GCC Patches References: <20221021232922.1093229-1-polacek@redhat.com> From: Jason Merrill In-Reply-To: <20221021232922.1093229-1-polacek@redhat.com> 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=-12.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_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 10/21/22 19:29, Marek Polacek wrote: > This test ICEs in C++23 because we reach the new code in do_auto_deduction: > > 30468 if (cxx_dialect >= cxx23 > 30469 && context == adc_return_type > 30470 && (!AUTO_IS_DECLTYPE (auto_node) > 30471 || !unparenthesized_id_or_class_member_access_p (init)) > 30472 && (r = treat_lvalue_as_rvalue_p (maybe_undo_parenthesized_ref (init), > 30473 /*return*/true))) > > where 'init' is "VIEW_CONVERT_EXPR<<<< error >>>>(y)", and then the move > in treat_lvalue_as_rvalue_p returns error_mark_node whereupon > set_implicit_rvalue_p crashes. > > I don't think such V_C_Es are useful so let's not create them. But that > won't fix the ICE so I'm checking the return value of move. A structured > bindings decl can have an error type, that is set in cp_finish_decomp: > > 8908 TREE_TYPE (first) = error_mark_node; > > therefore I think treat_lvalue_as_rvalue_p just needs to cope. > > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? > > PR c++/107276 > > gcc/cp/ChangeLog: > > * typeck.cc (treat_lvalue_as_rvalue_p): Check the return value of move. > > gcc/ChangeLog: > > * tree.cc (maybe_wrap_with_location): Don't create a location wrapper > when the type is erroneous. > > gcc/testsuite/ChangeLog: > > * g++.dg/cpp2a/decomp4.C: New test. > --- > gcc/cp/typeck.cc | 7 ++++++- > gcc/testsuite/g++.dg/cpp2a/decomp4.C | 8 ++++++++ > gcc/tree.cc | 3 ++- > 3 files changed, 16 insertions(+), 2 deletions(-) > create mode 100644 gcc/testsuite/g++.dg/cpp2a/decomp4.C > > diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc > index 16e7d85793d..5ca191759f6 100644 > --- a/gcc/cp/typeck.cc > +++ b/gcc/cp/typeck.cc > @@ -10726,7 +10726,12 @@ treat_lvalue_as_rvalue_p (tree expr, bool return_p) > if (DECL_CONTEXT (retval) != current_function_decl) > return NULL_TREE; > if (return_p) > - return set_implicit_rvalue_p (move (expr)); > + { > + expr = move (expr); > + if (expr == error_mark_node) > + return NULL_TREE; > + return set_implicit_rvalue_p (expr); > + } > > /* if the operand of a throw-expression is a (possibly parenthesized) > id-expression that names an implicitly movable entity whose scope does not > diff --git a/gcc/testsuite/g++.dg/cpp2a/decomp4.C b/gcc/testsuite/g++.dg/cpp2a/decomp4.C > new file mode 100644 > index 00000000000..28b3f172b53 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp2a/decomp4.C > @@ -0,0 +1,8 @@ > +// PR c++/107276 > +// { dg-do run { target c++20 } } > + > +auto f(auto x) { > + auto [y] = x; // { dg-error "cannot decompose" } > + return y; > +} > +int i = f(0); > diff --git a/gcc/tree.cc b/gcc/tree.cc > index 81a6ceaf181..4e5b1df4d85 100644 > --- a/gcc/tree.cc > +++ b/gcc/tree.cc > @@ -14352,7 +14352,8 @@ maybe_wrap_with_location (tree expr, location_t loc) > > /* For now, don't add wrappers to exceptional tree nodes, to minimize > any impact of the wrapper nodes. */ > - if (EXCEPTIONAL_CLASS_P (expr)) > + if (EXCEPTIONAL_CLASS_P (expr) > + || (TREE_TYPE (expr) && EXCEPTIONAL_CLASS_P (TREE_TYPE (expr)))) I think check error_operand_p instead; I don't think it makes sense to look for other exceptional nodes in TREE_TYPE. Jason