Topic: Allow zero size arrays and let them occupy


Author: Andrey Semashev <andrey.semashev@gmail.com>
Date: Wed, 6 Jul 2016 14:34:47 +0300
Raw View
On 07/06/16 11:59, Bengt Gustafsson wrote:
> Den m=C3=A5ndag 4 juli 2016 kl. 18:30:24 UTC+2 skrev Nicol Bolas:
>     On Monday, July 4, 2016 at 11:15:15 AM UTC-4, Bengt Gustafsson wrote:
>
>         1. Allow zero sized arrays in C++.
>
>         No code would break by just allowing something previously
>         forbidden. The problem with allowing this could have been to
>         make up ones mind about what size such an array should report.
>
>
>     Allow them to do... what?
>
> Be declared. Have their address taken. Said address being being that of
> the first addressable byte after the previous variable in the scope.
>  From this follows that begin() and end() on zero sized arrays both
> return this address, so that range based for loops 0 times.

It would mean that sizeof would return 0 for that array. This breaks=20
assumption of that it can never happen in the existing code.

It would also mean that address of the array would be the same as the=20
address of the following object, assuming the object's alignment=20
permits. It breaks aliasing rules.

--=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/577CECD7.2050807%40gmail.com.

.


Author: Tony V E <tvaneerd@gmail.com>
Date: Thu, 7 Jul 2016 17:52:09 -0400
Raw View
--089e010d81c6b311c4053712b265
Content-Type: text/plain; charset=UTF-8

On Wed, Jul 6, 2016 at 5:00 AM, Bengt Gustafsson <
bengt.gustafsson@beamways.com> wrote:

> One of the (current) SFINAE rules is that attempting to create an array of
>> size zero causes the template instantiation to fail.
>> This forces the compiler to consider other possible candidates.
>> Allowing zero sized arrays would cause the instantiation to succeed,
>> which will obviously change the behaviour of existing programs.
>>
>>   Tobias
>>
>>
>> This is unfortunate. But can you come up with a case where such SFINAE
> can actually be used? To me it seems that to use this rule you would have
> to create a zero sized array first and then try to call a function
> templated on the array size with it. But then you get a hard error
> for trying to make the array (under current rules)! Maybe there are more
> complicated cases but I think there has to be at least one that is possible
> to use today, or this SFINAE rule is superflous. Given actual uses of this
> rule an assessment can be made whether breaking such code can be accepted.
>

Since most compilers already accept zero-sized arrays, I've always used -1
instead of 0.

--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAOHCbiuuOi4YEmUSuEYS3K_tHHD_M2juiNKB32RqA_xvhG%2B8jg%40mail.gmail.com.

--089e010d81c6b311c4053712b265
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><div class=3D"gmail_extra"><br><div class=3D"gmail_quo=
te">On Wed, Jul 6, 2016 at 5:00 AM, Bengt Gustafsson <span dir=3D"ltr">&lt;=
<a href=3D"mailto:bengt.gustafsson@beamways.com" target=3D"_blank">bengt.gu=
stafsson@beamways.com</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_q=
uote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1e=
x"><div dir=3D"ltr"><span class=3D""><blockquote class=3D"gmail_quote" styl=
e=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex=
"><div dir=3D"ltr"><div>One of the (current) SFINAE rules is that attemptin=
g to create an array of size zero causes the template instantiation to fail=
..<br></div><div>This forces the compiler to consider other possible candida=
tes.<br>Allowing zero sized arrays would cause the instantiation to succeed=
, which will obviously change the behaviour of existing programs.<br><br>=
=C2=A0 Tobias<br><br></div><div><br></div></div></blockquote></span><div>Th=
is is unfortunate. But can you come up with a case where such SFINAE can ac=
tually be used? To me it seems that to use this rule you would have to crea=
te a zero sized array first and then try to call a function templated on th=
e array size with it. But then you get a hard error</div><div>for trying to=
 make the array (under current rules)! Maybe there are more complicated cas=
es but I think there has to be at least one that is possible to use today, =
or this SFINAE rule is superflous. Given actual uses of this rule an assess=
ment can be made whether breaking such code can be accepted.</div></div></b=
lockquote><div><br></div></div>Since most compilers already accept zero-siz=
ed arrays, I&#39;ve always used -1 instead of 0.<br><br></div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAOHCbiuuOi4YEmUSuEYS3K_tHHD_M2juiNKB=
32RqA_xvhG%2B8jg%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">h=
ttps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAOHCbiuuOi4YEm=
USuEYS3K_tHHD_M2juiNKB32RqA_xvhG%2B8jg%40mail.gmail.com</a>.<br />

--089e010d81c6b311c4053712b265--

.