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 24ABB3856970 for ; Tue, 16 May 2023 15:38:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 24ABB3856970 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=1684251495; 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; bh=g/33z/cqW0erHeuetmKWIz5X1E+BldAwae7g/ckl74A=; b=dkUK1IjeRql/6QRYKDX3T/+7SfAuLW0oqnHFV6uIFtLUKRotyVT/9fM/bLVMlGhnegEFLE toGQIWXhbqIXqVLOev1kbqwsqNcRXQU9IyQY1JjF7FDoy2AYBeHQl4MluXdpp+SiuaBC2J vxapM7YsLKFjJdEBl/tWcz6Uh9fOHnI= 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-435-XQwDteOHNLayCFiSa0hO2g-1; Tue, 16 May 2023 11:38:14 -0400 X-MC-Unique: XQwDteOHNLayCFiSa0hO2g-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-61b59e13fbeso157218106d6.0 for ; Tue, 16 May 2023 08:38:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684251493; x=1686843493; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=g/33z/cqW0erHeuetmKWIz5X1E+BldAwae7g/ckl74A=; b=JilCuWOZ6YVN7aAEy8+gC3ltF3SV/MhkgVgrswnesId4/Xb/ynV5jZpbNe4pvunrbq PABVdJnHKN8P2UGApuKMfSQ2H5QxLbigL1tC0qYY3OnR8zXwxpcbdrCi27rmuPDE9TPT d9tP62RKABZ6rQGHqnW56EgIrHETGBO79AzPuX+s3s0HoUQNvijxHRolKVrDzMeqEgYB R9GP9utqgsaWqrb1k4dzmp5W5/AcZhbF9uAerm4zGvOyl5yugHnIXS4GJUXJDpUeumeZ toh31BgHGjwblJHrkbJRw+5yy7672/6EekgWYqhbKnOOR/vcdsLJB8urZ6iqnQVtnYSw 2gNw== X-Gm-Message-State: AC+VfDy34lYcRggZs3vsz8D97vlCT4fcdmB6JXe0shKVS+vf+tH6j1O6 wY+hU4LT3D7xGwMaQ6ulcJqe1HXL/F0ctTUEZjTKsIQPe3YumDPR+KJI7eiUmVO6GCRt5hKWEKK f3tb6Z1zKxl1pUZQUHQFX/8S+TFvRC9q+kNqp4IjZCQ5qUP0jvl2YwnwncsAIlzUgq4Khr0D7R3 w= X-Received: by 2002:ad4:5cc1:0:b0:5e9:2d8c:9a21 with SMTP id iu1-20020ad45cc1000000b005e92d8c9a21mr69212118qvb.32.1684251493493; Tue, 16 May 2023 08:38:13 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ70wmv+fnvagac0o8LV/djwV9T08oyJG3vqsSzKZhCNFt6wqfQyF6jCyOfvfvKOUd/SDoMf0g== X-Received: by 2002:ad4:5cc1:0:b0:5e9:2d8c:9a21 with SMTP id iu1-20020ad45cc1000000b005e92d8c9a21mr69212061qvb.32.1684251493006; Tue, 16 May 2023 08:38:13 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id o14-20020a0c8c4e000000b00621268e14efsm5740115qvb.55.2023.05.16.08.38.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 May 2023 08:38:12 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: desig init in presence of list ctor [PR109871] Date: Tue, 16 May 2023 11:38:11 -0400 Message-ID: <20230516153811.3515353-1-ppalka@redhat.com> X-Mailer: git-send-email 2.40.1.552.g91428f078b MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-13.7 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,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: 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. 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 +} -- 2.40.1.552.g91428f078b