Topic: Unused elements of structured bind
Author: Andrew Tomazos <andrewtomazos@gmail.com>
Date: Tue, 11 Dec 2018 19:27:35 +1000
Raw View
--000000000000d60b52057cbbb1d5
Content-Type: text/plain; charset="UTF-8"
Now that structured bindings are in the wild, we're frequently seeing an
issue in practice, whereby there are unused members of a structured bind
that trigger the unused diagnostic:
auto& [a,b] = f();
g(a);
// error: b unused
Clearly one can:
(void)b;
but it seems awkward.
I suspect this is coming up a lot because very often you want to
"destructure" something into its component parts, but only use a subset of
those components. When the similar situation comes up for function
parameters, people typically comment out (/*paramname*/) the parameter
name, but you can't do that with a structured binding.
Was there any reason why we don't allow blank members of a structured
binding, so you can write this:
auto& [a, /*b*/] = f();
I vaguely remember this coming up during design discussion, but don't quite
remember why there was opposition?
--
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/CAB%2B4KHKJ58BDHPk6mVDGvvkdVwCkp5nzp%3D3ZYPdHgfHRduVZvA%40mail.gmail.com.
--000000000000d60b52057cbbb1d5
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Now that structured bindings are in the wild, we're fr=
equently seeing an issue in practice, whereby there are unused members of a=
structured bind that trigger the unused diagnostic:<div><br></div><div>=C2=
=A0 =C2=A0auto& [a,b] =3D f();</div><div>=C2=A0 =C2=A0g(a);</div><div>=
=C2=A0 =C2=A0// error: b unused</div><div><br></div><div>Clearly one can:<b=
r></div><div><br></div><div>=C2=A0 (void)b;</div><div><br></div><div>but it=
seems awkward.</div><div><br></div><div>I suspect this is coming up a lot =
because very often you want to "destructure" something into its c=
omponent parts, but only use a subset of those components.=C2=A0 When the s=
imilar situation comes up for function parameters, people typically comment=
out (/*paramname*/) the parameter name, but you can't do that with a s=
tructured binding.</div><div><br></div><div>Was there any reason why we don=
't allow blank members of a structured binding, so you can write this:<=
/div><div><br></div><div><div>=C2=A0 =C2=A0auto& [a, /*b*/] =3D f();</d=
iv><br class=3D"gmail-Apple-interchange-newline"></div><div>I vaguely remem=
ber this coming up during design discussion, but don't quite remember w=
hy there was opposition?</div><div><br></div><div></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/CAB%2B4KHKJ58BDHPk6mVDGvvkdVwCkp5nzp%=
3D3ZYPdHgfHRduVZvA%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAB%2B4KHKJ58=
BDHPk6mVDGvvkdVwCkp5nzp%3D3ZYPdHgfHRduVZvA%40mail.gmail.com</a>.<br />
--000000000000d60b52057cbbb1d5--
.
Author: Barry Revzin <barry.revzin@gmail.com>
Date: Tue, 11 Dec 2018 08:08:46 -0800 (PST)
Raw View
------=_Part_2154_2078923738.1544544526475
Content-Type: multipart/alternative;
boundary="----=_Part_2155_1666969722.1544544526476"
------=_Part_2155_1666969722.1544544526476
Content-Type: text/plain; charset="UTF-8"
On Tuesday, December 11, 2018 at 3:27:51 AM UTC-6, Andrew Tomazos wrote:
>
> Now that structured bindings are in the wild, we're frequently seeing an
> issue in practice, whereby there are unused members of a structured bind
> that trigger the unused diagnostic:
>
> auto& [a,b] = f();
> g(a);
> // error: b unused
>
Do you have an example? Neither gcc nor clang emit a warning with -Wall
-Wextra on something like:
struct X { int i, j; };
int get(X x) {
auto& [i, j] = x;
return i;
}
--
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/fc9878ca-44e1-436a-b3a5-c7f90998e061%40isocpp.org.
------=_Part_2155_1666969722.1544544526476
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Tuesday, December 11, 2018 at 3:27:51 AM UTC-6,=
Andrew Tomazos wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;=
margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=
=3D"ltr">Now that structured bindings are in the wild, we're frequently=
seeing an issue in practice, whereby there are unused members of a structu=
red bind that trigger the unused diagnostic:<div><br></div><div>=C2=A0 =C2=
=A0auto& [a,b] =3D f();</div><div>=C2=A0 =C2=A0g(a);</div><div>=C2=A0 =
=C2=A0// error: b unused</div></div></blockquote><div><br></div><div>Do you=
have an example? Neither gcc nor clang emit a warning with -Wall -Wextra o=
n something like:</div><div><br></div><div><div class=3D"prettyprint" style=
=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187);=
border-style: solid; border-width: 1px; overflow-wrap: break-word;"><code =
class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #=
008;" class=3D"styled-by-prettify">struct</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> X </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-pret=
tify">int</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
i</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> j</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">};</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">int</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify=
">get</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify">X x</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">)</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color:=
#008;" class=3D"styled-by-prettify">auto</span><font color=3D"#000000"><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">&</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">[</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify">i</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> j</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">]</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> <=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> x</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br></span></font><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify">=C2=A0 =C2=A0 </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">return</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> i</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">}</span></div></code></div><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" 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/fc9878ca-44e1-436a-b3a5-c7f90998e061%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/fc9878ca-44e1-436a-b3a5-c7f90998e061=
%40isocpp.org</a>.<br />
------=_Part_2155_1666969722.1544544526476--
------=_Part_2154_2078923738.1544544526475--
.
Author: Ross Smith <ross.smith@otoy.com>
Date: Wed, 12 Dec 2018 09:38:04 +1300
Raw View
On 2018-12-12 05:08, Barry Revzin wrote:
>=20
> On Tuesday, December 11, 2018 at 3:27:51 AM UTC-6, Andrew Tomazos wrote:
>=20
> Now that structured bindings are in the wild, we're frequently
> seeing an issue in practice, whereby there are unused members of a
> structured bind that trigger the unused diagnostic:
>=20
> =C2=A0 =C2=A0auto& [a,b] =3D f();
> =C2=A0 =C2=A0g(a);
> =C2=A0 =C2=A0// error: b unused
>=20
> Do you have an example? Neither gcc nor clang emit a warning with -Wall=
=20
> -Wextra on something like:
>=20
> struct X { int i, j; };
> int get(X x) {
> auto& [i, j] =3D x;
> return i;
> }
This problem seems to have been fixed in the compilers now. GCC 7.3 does
warn about the above code (with -Wall), but GCC 8.2 doesn't. However,
GCC 8.2 does warn about other unused variables - if you add a gratuitous
"int k =3D 42;" to the above (and never use k), you get a warning. The
same thing (no warning about unused structured binding, but a warning
about a "legitimate" unused variable) happens with Clang 5.0, MSVC 2017,
and Xcode 10. So I think we can safely conclude that the compiler
vendors have been aware of this issue for a while now, and it's no
longer a problem.
Ross Smith
--=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/fb3e530a-1415-2808-7fb8-d4f42ed8d26b%40otoy.com.
.