From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11020 invoked by alias); 14 Feb 2020 08:13:15 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 10971 invoked by uid 89); 14 Feb 2020 08:13:06 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.4 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy= X-HELO: us-smtp-delivery-1.mimecast.com Received: from us-smtp-1.mimecast.com (HELO us-smtp-delivery-1.mimecast.com) (207.211.31.81) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 14 Feb 2020 08:13:05 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581667983; 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=2FQvedoLiiMZju4Xyp+uus5YIJUtI3C5qoJ6l9bTG/w=; b=LgEJWDCvO7IKOyWvfL4ygyzYBlzkKrRRmhDmZ7k4UeMU423AAVDcl1p5b8ctj9gmaCOooZ 6UgWmpG9EQCjMEjVrJ8rY9Xr5OyIbUuprP+rzZFcawPYE4FMQjMiKCeBSVIjX41ntl7SR8 ZqpTqNzUEBWzR6czLEQicY/xVlgwto4= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-239-Q7gJCVzMOMm7iU7AED8mrw-1; Fri, 14 Feb 2020 03:13:01 -0500 Received: by mail-wm1-f71.google.com with SMTP id u11so3082736wmb.4 for ; Fri, 14 Feb 2020 00:13:01 -0800 (PST) Return-Path: Received: from [192.168.123.229] ([193.85.242.128]) by smtp.gmail.com with ESMTPSA id x11sm6193836wmg.46.2020.02.14.00.12.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 14 Feb 2020 00:12:58 -0800 (PST) Subject: Re: [PATCH] c++: Fix ICE with ill-formed array list-initialization [PR93712] To: Marek Polacek , GCC Patches References: <20200213195600.495394-1-polacek@redhat.com> From: Jason Merrill Message-ID: <2143009f-35d4-456d-78ac-46e748a55538@redhat.com> Date: Fri, 14 Feb 2020 08:13:00 -0000 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: <20200213195600.495394-1-polacek@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2020-02/txt/msg00844.txt.bz2 On 2/13/20 8:56 PM, Marek Polacek wrote: > My P0388R4 patch changed build_array_conv to create an identity > conversion at the start of the conversion chain. Hmm, an identity conversion of {} suggests that it has a type, which it doesn't in the language. I'm not strongly against it, but what was the reason for this change? > That was a sound change but now we crash in convert_like_real > > 7457 case ck_identity: > 7458 if (BRACE_ENCLOSED_INITIALIZER_P (expr)) > 7459 { > 7460 int nelts = CONSTRUCTOR_NELTS (expr); > 7461 if (nelts == 0) > 7462 expr = build_value_init (totype, complain); > 7463 else if (nelts == 1) > 7464 expr = CONSTRUCTOR_ELT (expr, 0)->value; > 7465 else > 7466 gcc_unreachable (); // HERE > 7467 } Right, this is assuming that any other {} will either be ill-formed or handled by ck_aggr or ck_list. How are we getting here without going through one of those? > in a test like this > > int f (int const (&)[2]) > { > return f({1, " "}); > } > > I considered fixing this when performing overload resolution (clang says > "no matching function for call to 'f'"), but then it occured to me that > we crash in different contexts too, so I'm just turning the assert into > an early return. > > Bootstrapped/regtested on x86_64-linux, ok for trunk? > > 2020-02-13 Marek Polacek > > PR c++/93712 - ICE with ill-formed array list-initialization. > * call.c (convert_like_real): Turn an assert into a return. > > * g++.dg/cpp0x/initlist-array11.C: New test. > --- > gcc/cp/call.c | 2 +- > gcc/testsuite/g++.dg/cpp0x/initlist-array11.C | 10 ++++++++++ > 2 files changed, 11 insertions(+), 1 deletion(-) > create mode 100644 gcc/testsuite/g++.dg/cpp0x/initlist-array11.C > > diff --git a/gcc/cp/call.c b/gcc/cp/call.c > index 51621b7dd87..eba0ed8041d 100644 > --- a/gcc/cp/call.c > +++ b/gcc/cp/call.c > @@ -7463,7 +7463,7 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, > else if (nelts == 1) > expr = CONSTRUCTOR_ELT (expr, 0)->value; > else > - gcc_unreachable (); > + return error_mark_node; > } > expr = mark_use (expr, /*rvalue_p=*/!convs->rvaluedness_matches_p, > /*read_p=*/true, UNKNOWN_LOCATION, > diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-array11.C b/gcc/testsuite/g++.dg/cpp0x/initlist-array11.C > new file mode 100644 > index 00000000000..7e76b588471 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp0x/initlist-array11.C > @@ -0,0 +1,10 @@ > +// PR c++/93712 - ICE with ill-formed array list-initialization. > +// { dg-do compile { target c++11 } } > + > +int f (const int (&)[2]); > + > +int g () > +{ > + const int (&r)[2] = {1, "foo"}; // { dg-error "invalid conversion" } > + return f({1, "foo"}); // { dg-error "invalid conversion" } > +} > > base-commit: 1d69147af203d4dcd2270429f90c93f1a37ddfff >