From patchwork Mon Mar 21 20:45:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1607914 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=ACOzmgSW; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KMmqq5mZ1z9s0r for ; Tue, 22 Mar 2022 07:46:30 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 417693889831 for ; Mon, 21 Mar 2022 20:46:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 417693889831 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1647895588; bh=VOHm5Bqz0ba4LujF2anJVZvP1YZTAlGwMx9uM/l/EYU=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=ACOzmgSWzMiReNEJv/LemGSSdWyRJ4Fz98vv5I4DzhNnUkoEzrCrlQUGWdGL3fdWy 2ftlDXtxMSSZbxLHsoSrzoFFUTsdf67MVLYm9EOLFNi6EJB3Zzfh6dpuuFFuVe2sNY ps+ksSGMp3fLb4yLBynV0pBy63lgbp5AvWpauhno= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 C55AC3857404 for ; Mon, 21 Mar 2022 20:45:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C55AC3857404 Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-355-9DQqpdDZPsi4THscOKz9Nw-1; Mon, 21 Mar 2022 16:45:44 -0400 X-MC-Unique: 9DQqpdDZPsi4THscOKz9Nw-1 Received: by mail-qt1-f198.google.com with SMTP id k1-20020ac85fc1000000b002e1c5930386so10143778qta.3 for ; Mon, 21 Mar 2022 13:45:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=VOHm5Bqz0ba4LujF2anJVZvP1YZTAlGwMx9uM/l/EYU=; b=Gs1P/apLOBZHyrDxOE7RwytNQeS4Ltt7qeTj7TcLIHDspmErOHWA532FGefhYYZM/e Gchser9d7A8SJ3AjntvHgbsKNcidKPHsj64fO/O3ihKcEHLOuOR7hn+h9w5b+QPSAE++ r4BXNgr9XU80sQC0Ma6+pIQZPINwvVnEVkw4K2uXsBsrD1NbO7JFznjYhtwanfmu2+64 RwPQ3FnFZRslOHiPJq1Woj9oXK7N8s/N9iFVdXjplIVbf+Uut6cZpumMtuIODxSNESMC irXD1gXwoDZ+TQMLWDru8sTg74OWlg2I2+2rBAZ8KiqLY6Wo87dr3xCAeQkO/jZKqdgY i8CQ== X-Gm-Message-State: AOAM531ezyyPmzMPo+0JbDuYh8WNhRAULMi6a56yIfcHYuDZsgqq+0CJ 3E3cfe92v3OGSuabg/BUi2UDjZZihUOYbQu7+DJg2clc+BZJLzGI3po+0kJbp3baUYvQ9sX/s3H jS7O3RLHXxW6NQrwx8hFVzEuDXMdUyy+4Knh58kIxoZs4tFp2r2A8C+zx0ZnBngACjw== X-Received: by 2002:a05:620a:4592:b0:67d:8ed9:8c37 with SMTP id bp18-20020a05620a459200b0067d8ed98c37mr13982403qkb.150.1647895543914; Mon, 21 Mar 2022 13:45:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQpsA3JVO149o0BtCasA4NT4TO4rCOoUOLbLXxHBPsQPUng2tKdLug3f+9IvV+Sf3lVfDmWQ== X-Received: by 2002:a05:620a:4592:b0:67d:8ed9:8c37 with SMTP id bp18-20020a05620a459200b0067d8ed98c37mr13982392qkb.150.1647895543395; Mon, 21 Mar 2022 13:45:43 -0700 (PDT) Received: from barrymore.redhat.com (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 c17-20020ac85a91000000b002e1dd8ae44bsm12599851qtc.29.2022.03.21.13.45.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 13:45:42 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: designator and anon struct [PR101767] Date: Mon, 21 Mar 2022 16:45:40 -0400 Message-Id: <20220321204540.2408524-1-jason@redhat.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.3 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, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jason Merrill via Gcc-patches From: Jason Merrill Reply-To: Jason Merrill Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" We found .x in the anonymous struct, but then didn't find .y there; we should decide that means we're done with the struct rather than that the code is wrong. Tested x86_64-pc-linux-gnu, applying to trunk. PR c++/101767 gcc/cp/ChangeLog: * decl.cc (reshape_init_class): Back out of anon struct if a designator doesn't match. gcc/testsuite/ChangeLog: * g++.dg/ext/anon-struct10.C: New test. --- gcc/cp/decl.cc | 5 +++++ gcc/testsuite/g++.dg/ext/anon-struct10.C | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/anon-struct10.C base-commit: 70b8f43695b0e6fabc760d247ac83f354092b21d diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 8afda8264c4..375385e0013 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -6626,6 +6626,11 @@ reshape_init_class (tree type, reshape_iter *d, bool first_initializer_p, return error_mark_node; } + if (!field && ANON_AGGR_TYPE_P (type)) + /* Apparently the designator isn't for a member of this anonymous + struct, so head back to the enclosing class. */ + break; + if (!field || TREE_CODE (field) != FIELD_DECL) { if (complain & tf_error) diff --git a/gcc/testsuite/g++.dg/ext/anon-struct10.C b/gcc/testsuite/g++.dg/ext/anon-struct10.C new file mode 100644 index 00000000000..9b01bf3fada --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/anon-struct10.C @@ -0,0 +1,21 @@ +// PR c++/101767 +// { dg-do compile { target c++11 } } +// { dg-additional-options "-Wno-pedantic" } + +typedef struct { + struct { + int x; + }; + union { + int y; + float z; + }; +} S; + +void foo(void) +{ + [[maybe_unused]] S a = { + .x = 1, + .y = 0 + }; +}