From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) by sourceware.org (Postfix) with ESMTPS id 8B9323857C4E for ; Mon, 15 Nov 2021 18:14:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8B9323857C4E Received: by mail-lf1-x12c.google.com with SMTP id bi37so40950726lfb.5 for ; Mon, 15 Nov 2021 10:14:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=Y9pjxrfUNIL/d5hVl1LmGz2S4L7Ac+64BTpGBKjcXxA=; b=MBxiDjH1bgxydPxLS4yGRmc0UtGL2CZBLUbB6Ohwi9iF+s4QldaBymgLp7PyA+31gw 8sj61wkysCFRBE+XHBJruHYafcXtvhmuc+Re27W6dIeAXDP0KD+ojRzBf4FZc7iVhsGC /EZ+JR76BcQhRDD0JLlElb/3CqQ/eHi/EK6sA4u9P6I4qfURoiButFE9LJ4caLPPqbxu 1dmF/Nm6tzdQ4kaZPOPz88I+soReyODdGTHbS7yrxGwfHhZoD9DW3tRH1I8uEfhDmUvv k5Hbc2rUwL1CPuK2+Qlrs3okqaBDqlqIdwCpBZET9qY+BbDfiAyeJV/ckm7+pMmmbk0d 6yuA== X-Gm-Message-State: AOAM533JYJVtpJ1NQxlYNkqJLW3VI1jlQA1C1qNkZyraKFJxhtYiyHkz oDipDo9S/W4Po7gxo86q6eswIHgEpCfRNv19iP2ICXKvJdc= X-Google-Smtp-Source: ABdhPJxqhGDMX98eeKiIqf0DDUmv06Q8Spteej9aUitCqD48Twd7ljujnPjVNcYdKfypQvZMpfmab9YTqsjl9v9OdGk= X-Received: by 2002:a05:6512:ba7:: with SMTP id b39mr562767lfv.529.1637000052632; Mon, 15 Nov 2021 10:14:12 -0800 (PST) MIME-Version: 1.0 References: <20211107001723.2528944-1-wjwray@gmail.com> In-Reply-To: <20211107001723.2528944-1-wjwray@gmail.com> From: will wray Date: Mon, 15 Nov 2021 13:14:01 -0500 Message-ID: Subject: PING: [PATCH] c++: designated init of char array by string constant [PR55227] To: gcc-patches List Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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-List-Received-Date: Mon, 15 Nov 2021 18:14:16 -0000 The fixes test out, as does the FIXME that's fixed based on the fixes... Note that the bug causes bogus rejection of any designated initialization of char array from a string literal, except for the singular case where the string literal initializer size exactly matches the target char array size and is not enclosed in optional braces: typedef struct C { char id[4]; } C; C a = {.id = "abc"}; // g++ accepts iff sizeof(C::c) == sizeof("abc") C b = {.id = {"abc"}}; // g++ rejects valid (gcc accepts) C c = {.id = "a"}; // g++ rejects valid (gcc accepts) I'd expect this to be common in C code bases, so the bug would be hit in any attempt to compile with g++. From the bugzilla comments, it seems that the following 'workaround' is being used: C d = {{.id = "a"}}; // g++ accepts invalid (gcc rejects) which 'works' in this case but is completely borked, consider: struct name {char first[32], second[32], third[32];}; name DMR {{.first = "Dennis"}, {.third = "Ritchie"}}; Only g++ accepts, ignores the designators, interprets as positional, and generates correspondingly invalid output: DMR: .string "Dennis" .zero 25 .string "Ritchie" .zero 24 .zero 32