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 590413858C83 for ; Tue, 16 May 2023 16:17:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 590413858C83 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=1684253870; 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=ayRShr1f6qmmfQIMHhQGwwNuFUT0aLaBOshoSdPfoU4=; b=d/cf40nKUvH4vkU46TecQq7hlly3/e5FbqmYLeVrIq5hqyf9/9ZimVj3StqJKrMeVSbhJ2 IM1Co+KdAdEl8iFE0jpKz9lWJyr00o2vzgSEgiiEHThKFDEmQ8ITYTeAWKeXn/hcH43k4c 6cQKoU07YXcBIzxSUz3ZDc2ORZCqQNM= 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-581-oBiUXNC-PLmfH4JmTf3xBQ-1; Tue, 16 May 2023 12:17:48 -0400 X-MC-Unique: oBiUXNC-PLmfH4JmTf3xBQ-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-61b59e13fbeso157700256d6.0 for ; Tue, 16 May 2023 09:17:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684253868; x=1686845868; 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=ayRShr1f6qmmfQIMHhQGwwNuFUT0aLaBOshoSdPfoU4=; b=KVfHW4HvQDV6XjYhAlaRFrrn1w2k1bQtX15Y1tqdTdsVzxlyYvh6kttQbaEoznjcNz wDr9iZS/FgYCrS7mUL8REN3i0mS9igaslFLOFQ6KU9mdAkIYUJWKkaJCCyi6zY3/1wCs bOfjqsY60V4yZ5N15xSr4kSzRdtKJFaQxyjS8IXxnnd+bJS9woxQIOHpJn/ICnwuzUvB B0SNoNpuEDJL5K4YEEZhVwZxe5F73gfYncacQIGawLmNboG7KaVHCEimys95Ne/hgIh6 DNN4TmidAkzWc5ZTuY96NaT5I1i4m4Kz/H+VWOFVTAsx+MeobEd3zllN22q9DcHw231N 6dZw== X-Gm-Message-State: AC+VfDxHnV8buNkkv7liSJ6BHc4aq3Z2T8nrH+ovvjHmp0tHAHjI8mxd K/EYEmWccL5d6lhm26fVTzdgZfmcN8XJPCgEGXJWHVO2Ccxr5Yrf+VN6MX8qO9mxhJ5eALUG/3Q ZHyY71OtourXZDcxFBw== X-Received: by 2002:a05:6214:48b:b0:5ef:486a:505e with SMTP id pt11-20020a056214048b00b005ef486a505emr63268406qvb.41.1684253868178; Tue, 16 May 2023 09:17:48 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4J6z6kV9ROyelAX4w2wTnALy9Knop04RbFcESPUNoWgFoMw1gTMNHmW8rHSLuN+7eHzKoGbQ== X-Received: by 2002:a05:6214:48b:b0:5ef:486a:505e with SMTP id pt11-20020a056214048b00b005ef486a505emr63268367qvb.41.1684253867847; Tue, 16 May 2023 09:17:47 -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 g17-20020a0cf851000000b00621430707f7sm5116163qvo.83.2023.05.16.09.17.46 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 16 May 2023 09:17:47 -0700 (PDT) Message-ID: Date: Tue, 16 May 2023 12:17:45 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.1 Subject: Re: [PATCH] c++: desig init in presence of list ctor [PR109871] To: Patrick Palka , gcc-patches@gcc.gnu.org References: <20230516153811.3515353-1-ppalka@redhat.com> From: Jason Merrill In-Reply-To: <20230516153811.3515353-1-ppalka@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=-14.1 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,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE 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 5/16/23 11:38, Patrick Palka wrote: > add_list_candidates has logic to reject designated initialization of a > non-aggregate type, but this is inadvertendly being suppressed if the type > has a list constructor due to the order of case analysis, which in the > below testcase leads to us incorrectly treating the list initializer as > an ordinary non-designated one. This patch fixes this by making us check > for invalid designated initialization sooner. > > Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for > trunk and perhaps 13? IIUC desig init is C++20 but we also accept it > with a pedwarn in earlier dialects, so not sure if this'd be suitable > for backporting. OK. > PR c++/109871 > > gcc/cp/ChangeLog: > > * call.cc (add_list_candidates): Check for invalid > designated initialization sooner, even for types that have > a list constructor. > > gcc/testsuite/ChangeLog: > > * g++.dg/cpp0x/desig6.C: New test. > --- > gcc/cp/call.cc | 16 ++++++++-------- > gcc/testsuite/g++.dg/cpp0x/desig6.C | 16 ++++++++++++++++ > 2 files changed, 24 insertions(+), 8 deletions(-) > create mode 100644 gcc/testsuite/g++.dg/cpp0x/desig6.C > > diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc > index 48611bb16a3..908374a43c9 100644 > --- a/gcc/cp/call.cc > +++ b/gcc/cp/call.cc > @@ -4129,6 +4129,14 @@ add_list_candidates (tree fns, tree first_arg, > if (CONSTRUCTOR_NELTS (init_list) == 0 > && TYPE_HAS_DEFAULT_CONSTRUCTOR (totype)) > ; > + else if (CONSTRUCTOR_IS_DESIGNATED_INIT (init_list) > + && !CP_AGGREGATE_TYPE_P (totype)) > + { > + if (complain & tf_error) > + error ("designated initializers cannot be used with a " > + "non-aggregate type %qT", totype); > + return; > + } > /* If the class has a list ctor, try passing the list as a single > argument first, but only consider list ctors. */ > else if (TYPE_HAS_LIST_CTOR (totype)) > @@ -4140,14 +4148,6 @@ add_list_candidates (tree fns, tree first_arg, > if (any_strictly_viable (*candidates)) > return; > } > - else if (CONSTRUCTOR_IS_DESIGNATED_INIT (init_list) > - && !CP_AGGREGATE_TYPE_P (totype)) > - { > - if (complain & tf_error) > - error ("designated initializers cannot be used with a " > - "non-aggregate type %qT", totype); > - return; > - } > > /* Expand the CONSTRUCTOR into a new argument vec. */ > vec *new_args; > diff --git a/gcc/testsuite/g++.dg/cpp0x/desig6.C b/gcc/testsuite/g++.dg/cpp0x/desig6.C > new file mode 100644 > index 00000000000..8d4cf483176 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp0x/desig6.C > @@ -0,0 +1,16 @@ > +// PR c++/109871 > +// { dg-do compile { target c++11 } } > +// { dg-options "" } > + > +#include > + > +struct vector { > + vector(std::initializer_list); // #1 > + vector(int); // #2 > +}; > + > +void f(vector); > + > +int main() { > + f({.blah = 42}); // { dg-error "designated" } previously incorrectly selected #2 > +}