Date: Fri, 1 May 2026 22:13:54 +0200
pt., 1 maj 2026 o 21:16 Maciej Polański via Std-Discussion
<std-discussion_at_[hidden]> napisał(a):
>
> That's valuable input! So there is a consensus that the zero-size array
> is erroneous.
>
> I also discovered that this is explicitly prohibited by [dcl.init.aggr]
> 9.5.2.10.
> "An array of unknown bound shall not be initialized with an empty
> braced-init-list {}"
> https://eel.is/c++draft/dcl.init.aggr#10
>
> I wonder if there is a rationale behind keeping zero-size arrays as the
> default. My guess is that it's a legacy of the initial C++11
> implementations.
>
> What concerns me:
> 1. C/C++ is seen as difficult to learn by young programmers.
> 2. The implementation of arrays is effective, yet quite unusual compared
> to other languages, and it can be difficult to understand at first.
> 3. And yet some compilers have a trap for beginners, which is something
> to be aware of. Silent acceptance of obvious errors can hinder
> subsequent debugging attempts.
>
> I thought something should be changed, but now I've lost my confidence.
>
Use proper tools, like instead of `int[]` use `std::array`, it even
can make code simpler:
```
std::array foo = { 1, 2, 3 };
```
> Thanks,
> Maciej
>
> W dniu 27.04.2026 o 20:10, Nate Eldredge pisze:
> > GCC and Clang only claim standard compliance when -pedantic is used, and with this option, they both issue a diagnostic (an error for GCC, a warning for Clang). So I don't think your proposed text would require them to change anything.
> >
> > I wouldn't say they are treating it as "legal". They both provide zero-length arrays as a clearly documented extension, which they readily acknowledge is non-standard. A user who wants to avoid such extensions and receive all standard-mandated diagnostics should know to use -pedantic.
> >
> > You may very well think that the -pedantic behavior should be their default, to avoid such instances of confusion, and you could take that up with their developers, but it's outside the jurisdiction of the standard.
> >
> >> On Apr 27, 2026, at 11:51, Maciej Polański via Std-Discussion <std-discussion_at_[hidden]> wrote:
> >>
> >> Dear Group,
> >>
> >> Please let me know if the world needs this fix and if it could count as an editorial. So:
> >>
> >> The following variable declaration is not allowed and should result in an error:
> >> int arr[];
> >> However, due to an unclear wording in The Standard, the following statement is legal on many compilers, though UB:
> >> int arr[]{};
> >> I'll be glad to be proved wrong if there's a legal use for `int arr[]{}`.
> >>
> >> The current "state of the art" is that GCC and Clang allow a zero-sized array if the bounds are omitted and followed by an empty initializer. MSVC is more cautious and prevents developers from experiencing the consequences of their errors. I suppose the authors of all the compilers think they are compliant on this issue.
> >> https://godbolt.org/z/jbbcnqP9K
> >>
> >> In my opinion, the problem lies in interpreting the unfortunate wording of The Standard [decl.array] "9.3.4.5 Arrays - 7" without proper context:
> >> "An array bound may also be omitted when an object (but not a non-static data member) of array type is initialized and the declarator is followed by an initializer"
> >> https://eel.is/c++draft/dcl.decl#dcl.array-7
> >> This paragraph does not explicitly exclude empty initializers. In the case of arrays, "empty" means "nothing," which may result in undefined behavior (UB).
> >>
> >> But, in my opinion, the compiler should interpret the paragraph above in the context of the following:
> >> 1. "[decl.array] 9.3.4.5 Arrays - 1" That explicitly states that the array bound "N shall be greater than zero".
> >> 2. "[dcl.init.general] 9.5.1 General - 16.5" That describes use of an initializer for an array and requires "1 <= i <= k," where k is the initializer size.
> >>
> >> In my opinion, the solution could be as simple as rewording "followed by an initializer" to "followed by a non-empty initializer."
> >>
> >>
> >> This issue surfaced during, not directly related to it, StackOverflow discussion:
> >> https://stackoverflow.com/questions/78941074/accessing-and-modifying-array-elements/78941410#78941410
> >> Among other mistakes, the author used a zero-size array. As the StackOverflow question showed, this mistake happens among beginners. Perhaps some think that zero-size arrays are self-extending, as many scripting languages have this feature. Therefore, it could be helpful to prevent zero-size array cases.
> >>
> >> The arguments for classifying this as an editorial are as follows:
> >> It is obvious that no zero-size arrays exist.
> >> Rule "Unclear writing, when the intention of the text in question is well-known to the committee, but the presentation could be clearer".
> >> There should also be no impact on existing programs, as those using zero-size are likely already broken.
> >> Against:
> >> This removes UB, which may affect some really exotic cases. Such changes may require formal paper.
> >>
> >> Even though I have a hard time accepting criticism, I welcome all opinions :)
> >>
> >> Maciej Polański
> >> MaciejPolanski75_at_[hidden]
> >>
> >> --
> >> Std-Discussion mailing list
> >> Std-Discussion_at_[hidden]
> >> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
> --
> Std-Discussion mailing list
> Std-Discussion_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
<std-discussion_at_[hidden]> napisał(a):
>
> That's valuable input! So there is a consensus that the zero-size array
> is erroneous.
>
> I also discovered that this is explicitly prohibited by [dcl.init.aggr]
> 9.5.2.10.
> "An array of unknown bound shall not be initialized with an empty
> braced-init-list {}"
> https://eel.is/c++draft/dcl.init.aggr#10
>
> I wonder if there is a rationale behind keeping zero-size arrays as the
> default. My guess is that it's a legacy of the initial C++11
> implementations.
>
> What concerns me:
> 1. C/C++ is seen as difficult to learn by young programmers.
> 2. The implementation of arrays is effective, yet quite unusual compared
> to other languages, and it can be difficult to understand at first.
> 3. And yet some compilers have a trap for beginners, which is something
> to be aware of. Silent acceptance of obvious errors can hinder
> subsequent debugging attempts.
>
> I thought something should be changed, but now I've lost my confidence.
>
Use proper tools, like instead of `int[]` use `std::array`, it even
can make code simpler:
```
std::array foo = { 1, 2, 3 };
```
> Thanks,
> Maciej
>
> W dniu 27.04.2026 o 20:10, Nate Eldredge pisze:
> > GCC and Clang only claim standard compliance when -pedantic is used, and with this option, they both issue a diagnostic (an error for GCC, a warning for Clang). So I don't think your proposed text would require them to change anything.
> >
> > I wouldn't say they are treating it as "legal". They both provide zero-length arrays as a clearly documented extension, which they readily acknowledge is non-standard. A user who wants to avoid such extensions and receive all standard-mandated diagnostics should know to use -pedantic.
> >
> > You may very well think that the -pedantic behavior should be their default, to avoid such instances of confusion, and you could take that up with their developers, but it's outside the jurisdiction of the standard.
> >
> >> On Apr 27, 2026, at 11:51, Maciej Polański via Std-Discussion <std-discussion_at_[hidden]> wrote:
> >>
> >> Dear Group,
> >>
> >> Please let me know if the world needs this fix and if it could count as an editorial. So:
> >>
> >> The following variable declaration is not allowed and should result in an error:
> >> int arr[];
> >> However, due to an unclear wording in The Standard, the following statement is legal on many compilers, though UB:
> >> int arr[]{};
> >> I'll be glad to be proved wrong if there's a legal use for `int arr[]{}`.
> >>
> >> The current "state of the art" is that GCC and Clang allow a zero-sized array if the bounds are omitted and followed by an empty initializer. MSVC is more cautious and prevents developers from experiencing the consequences of their errors. I suppose the authors of all the compilers think they are compliant on this issue.
> >> https://godbolt.org/z/jbbcnqP9K
> >>
> >> In my opinion, the problem lies in interpreting the unfortunate wording of The Standard [decl.array] "9.3.4.5 Arrays - 7" without proper context:
> >> "An array bound may also be omitted when an object (but not a non-static data member) of array type is initialized and the declarator is followed by an initializer"
> >> https://eel.is/c++draft/dcl.decl#dcl.array-7
> >> This paragraph does not explicitly exclude empty initializers. In the case of arrays, "empty" means "nothing," which may result in undefined behavior (UB).
> >>
> >> But, in my opinion, the compiler should interpret the paragraph above in the context of the following:
> >> 1. "[decl.array] 9.3.4.5 Arrays - 1" That explicitly states that the array bound "N shall be greater than zero".
> >> 2. "[dcl.init.general] 9.5.1 General - 16.5" That describes use of an initializer for an array and requires "1 <= i <= k," where k is the initializer size.
> >>
> >> In my opinion, the solution could be as simple as rewording "followed by an initializer" to "followed by a non-empty initializer."
> >>
> >>
> >> This issue surfaced during, not directly related to it, StackOverflow discussion:
> >> https://stackoverflow.com/questions/78941074/accessing-and-modifying-array-elements/78941410#78941410
> >> Among other mistakes, the author used a zero-size array. As the StackOverflow question showed, this mistake happens among beginners. Perhaps some think that zero-size arrays are self-extending, as many scripting languages have this feature. Therefore, it could be helpful to prevent zero-size array cases.
> >>
> >> The arguments for classifying this as an editorial are as follows:
> >> It is obvious that no zero-size arrays exist.
> >> Rule "Unclear writing, when the intention of the text in question is well-known to the committee, but the presentation could be clearer".
> >> There should also be no impact on existing programs, as those using zero-size are likely already broken.
> >> Against:
> >> This removes UB, which may affect some really exotic cases. Such changes may require formal paper.
> >>
> >> Even though I have a hard time accepting criticism, I welcome all opinions :)
> >>
> >> Maciej Polański
> >> MaciejPolanski75_at_[hidden]
> >>
> >> --
> >> Std-Discussion mailing list
> >> Std-Discussion_at_[hidden]
> >> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
> --
> Std-Discussion mailing list
> Std-Discussion_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
Received on 2026-05-01 20:14:10
