Topic: unused attribute (was: Add compiler time
Author: David Krauss <potswa@gmail.com>
Date: Thu, 1 May 2014 10:42:32 +0800
Raw View
On 2014-04-30, at 11:21 PM, Matthew Woehlke <mw_triad@users.sourceforge.net=
> wrote:
> void foo(int bar)
> {
> #if EXPR
> report(bar)
> #endif
> ...do some other stuff that doesn't use 'bar'...
> }
>=20
> Yes, this happens in real code. (Often the PP conditional is related to i=
f debugging is enabled or not.)
Then [[unused]] would only apply in the other PP branch. Perhaps it the sta=
ndard could recommend not warning about using an [[unused]] entity, but it =
still looks like a bug unless you do
void foo(
#if ! (EXPR)
[[unused]]
#endif
int bar)
The current solution to this issue is to artificially use (but not ODR-use)=
the variable:
#if EXPR
report(bar)
#else
(void) bar;
#endif
This "contains the damage" to the use site.
Of course you could wrap [[unused]] in a conditionally-defined macro, but y=
ou can do the same with the void cast (and that's already common practice).
> There's also the issue that not naming the argument makes the code harder=
to read ("what's this argument that you don't care about?").
I think that's solved by having a function prototype naming the variable, a=
nd leaving it anonymous only in the definition.
I do think [[unused]] might be a reasonable thing to have, but I wouldn't w=
ant it to be hobbled by a common use-case still involving later use. It mig=
ht be nice to tag globals and class members, and get a whole-program warnin=
g which could be specifically asked-for. But I don't know whether that's pr=
actical.
--=20
---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
.
Author: =?UTF-8?Q?David_Rodr=C3=ADguez_Ibeas?= <dibeas@ieee.org>
Date: Mon, 5 May 2014 16:24:45 -0400
Raw View
--001a11c1161418c7b804f8acec8a
Content-Type: text/plain; charset=UTF-8
And there is a simple standard solution to that:
On Wed, Apr 30, 2014 at 11:21 AM, Matthew Woehlke <
mw_triad@users.sourceforge.net> wrote:
>
> void foo(int bar)
> {
> #if EXPR
> report(bar)
>
#else
(void)bar;
> #endif
...do some other stuff that doesn't use 'bar'...
> }
>
> Yes, this happens in real code. (Often the PP conditional is related to if
> debugging is enabled or not.)
>
I agree that this is a common pattern, say for example:
int rc = doSomething();
assert(!rc); // no error
the approach I have been following is the one shown inlined in your code:
assert(!rc); (void)rc;
Not pretty, but functional.
--
---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
--001a11c1161418c7b804f8acec8a
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">And there is a simple standard solution to that:<div class=
=3D"gmail_extra"><br><br><div class=3D"gmail_quote">On Wed, Apr 30, 2014 at=
11:21 AM, Matthew Woehlke <span dir=3D"ltr"><<a href=3D"mailto:mw_triad=
@users.sourceforge.net" target=3D"_blank">mw_triad@users.sourceforge.net</a=
>></span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex"><br>
void foo(int bar)<br>
{<br>
#if EXPR<br>
=C2=A0 report(bar)<br></blockquote><div>=C2=A0</div><div>#else</div><div>(v=
oid)bar;</div><div>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"m=
argin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
#endif=C2=A0</blockquote><blockquote class=3D"gmail_quote" style=3D"margin:=
0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
=C2=A0 ...do some other stuff that doesn't use 'bar'...<br>
}<br>
<br>
Yes, this happens in real code. (Often the PP conditional is related to if =
debugging is enabled or not.)<br></blockquote><div><br>I agree that this is=
a common pattern, say for example:<br><br>int rc =3D doSomething();<br>
assert(!rc); =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
=C2=A0// no error=C2=A0<br><br>the approach I have been following is the o=
ne shown inlined in your code:=C2=A0<br><br>assert(!rc); (void)rc;<br><br>N=
ot pretty, but functional.</div></div></div></div>
<p></p>
-- <br />
<br />
--- <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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
--001a11c1161418c7b804f8acec8a--
.