C++ Logo

liaison

Advanced search

Re: [wg14/wg21 liaison] Array lvalues in braced initializer lists

From: will wray <wjwray_at_[hidden]>
Date: Sun, 1 Aug 2021 16:05:47 -0400
A similar issue was introduced with C++20 allowing paren-init of aggregates.
https://cpplang.slack.com/archives/C6K47F8TT/p1589643887464800

arthur-odwyer <https://app.slack.com/team/U5G2N458D> May 16th 2020
> Also speaking of copyable arrays, for anyone who hasn't seen it yet,
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95153
> std::is_copy_constructible<bool[2]> and std::is_copy_constructible<const
> void*[2]> are both true in C++20 because of
> aggregate-initialization-via-parentheses. bool a[2]; bool b[2](a); is
> valid C++20.


On Sun, Aug 1, 2021 at 4:02 PM will wray <wjwray_at_[hidden]> wrote:

> On Sun, Aug 1, 2021 at 2:56 PM Uecker, Martin via Liaison <
> liaison_at_[hidden]> wrote:
>
>> Would the following example change behavior?
>>
>> void foo(void)
>> {
>> void* b[3];
>> void* a[1][3] = { b };
>> }
>>
>
> Yes - I guess so.
>
> Is the initialization of 'a' ill-formed in C++? g++ rejects it with:
>
> *error: *array must be initialized with a brace-enclosed initializer
> 4 | const void* a[1][3] = { *b* };
> | *^*
> (it's accepted by clang++ and msvc, though, in pedantic/non-permissive mode)
> (on adding another brace it is accepted by all 3).
>
> There's a similar case with array-of-bool:
> #include <stdbool.h>
>
> void foo(void)
> {
> bool b[3];
> bool a[2][3] = { b };
> }
>
> Now, gcc accepts with no warning (gcc -std=c2x -pedantic -Werror)
> and clang rejects with -Werror because it diagnoses:
>
> *error: **address of array 'b' will always evaluate to 'true'
> [-Werror,-Wpointer-bool-conversion]*
> bool a[2][3] = { b };
> * ^*
>
>

Received on 2021-08-01 15:06:02