[prev in list] [next in list] [prev in thread] [next in thread] 

List:       cfe-commits
Subject:    Re: [PATCH] PR14253: 'warn_unused' attribute for unused warning for non-POD types
From:       Richard Smith <richard () metafoo ! co ! uk>
Date:       2013-07-21 7:55:42
Message-ID: CAOfiQqmD_UPVvs=SMdiNmjmXAsFL+oNwRqr2D2+PZtH3OEDmJQ () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


   case CXXTemporaryObjectExprClass:
-  case CXXConstructExprClass:
+  case CXXConstructExprClass: {
+    QualType Ty = getType();
+    if (const TagType *TT = Ty->getAs<TagType>()) {
+      const TagDecl *Tag = TT->getDecl();

You can use getType()->getAsCXXRecordDecl() here. Otherwise, looks fine,
thanks.

On Sat, Jul 20, 2013 at 4:24 PM, Lubos Lunak <l.lunak@suse.cz> wrote:

> On Tuesday 16 of July 2013, Lubos Lunak wrote:
> > On Tuesday 16 of July 2013, Lubos Lunak wrote:
> > > On Tuesday 16 of July 2013, Richard Smith wrote:
> > > > On Tue, Jul 16, 2013 at 12:50 PM, Lubos Lunak <l.lunak@suse.cz>
> wrote:
> > > > > On Tuesday 16 of July 2013, Richard Smith wrote:
> > > > > > Consider:
> > > > > >
> > > > > > {
> > > > > >   my_lock(my_mutex); // A
> > > > > >   my_lock ml(my_mutex); // B
> > > > > >   my_string("foo"); // C
> > > > > >   my_string ms("foo"); // D
> > > > > > }
> > > > > >
> > > > > > We never warn for a class that is in category (1). my_lock would
> be
> > > > > > in category (2), so we warn on A but not B. my_string would be in
> > > > > > category (3), so we warn on both C and D.
> > > > > >
> > > > > > Which of these does the warn_unused attribute model?
> > > > >
> > > > >  It doesn't model anything. It prevents disabling of the
> > > > > unused-variable warning for whatever type that has the attribute.
> > > >
> > > > So which of the above behaviors do you get? (Or do you get something
> > > > else?)
> > >
> > >  I think you are talking about something slightly different. This is
> > > about the (-W)unused-variable warning. So A and C obviously don't
> apply.
> >
> >  But since you ask, without looking at the code, presumably
> > (-W)unused-result has code similar to unused-variable that also disables
> > the warning if the type in question has non-trivial ctor/dtor, so you
> could
> > do a similar modification there to enable the warning for types with
> > warn_unused attribute.
>
>  The attached patch adds this functionality for the -Wunused-value warning.
>
> --
>  Lubos Lunak
>  l.lunak@suse.cz
>

[Attachment #5 (text/html)]

<div>   case CXXTemporaryObjectExprClass:</div><div>-  case \
CXXConstructExprClass:</div><div>+  case CXXConstructExprClass: {</div><div>+    \
QualType Ty = getType();</div><div>+    if (const TagType *TT = \
Ty-&gt;getAs&lt;TagType&gt;()) {</div> <div>+      const TagDecl *Tag = \
TT-&gt;getDecl();</div><div><br></div><div>You can use \
getType()-&gt;getAsCXXRecordDecl() here. Otherwise, looks fine, thanks.</div><br><div \
class="gmail_quote">On Sat, Jul 20, 2013 at 4:24 PM, Lubos Lunak <span \
dir="ltr">&lt;<a href="mailto:l.lunak@suse.cz" \
target="_blank">l.lunak@suse.cz</a>&gt;</span> wrote:<br> <blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Tuesday 16 of July \
2013, Lubos Lunak wrote:<br> &gt; On Tuesday 16 of July 2013, Lubos Lunak wrote:<br>
&gt; &gt; On Tuesday 16 of July 2013, Richard Smith wrote:<br>
&gt; &gt; &gt; On Tue, Jul 16, 2013 at 12:50 PM, Lubos Lunak &lt;<a \
href="mailto:l.lunak@suse.cz">l.lunak@suse.cz</a>&gt; wrote:<br> &gt; &gt; &gt; &gt; \
On Tuesday 16 of July 2013, Richard Smith wrote:<br> &gt; &gt; &gt; &gt; &gt; \
Consider:<br> &gt; &gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt; {<br>
&gt; &gt; &gt; &gt; &gt;   my_lock(my_mutex); // A<br>
&gt; &gt; &gt; &gt; &gt;   my_lock ml(my_mutex); // B<br>
&gt; &gt; &gt; &gt; &gt;   my_string(&quot;foo&quot;); // C<br>
&gt; &gt; &gt; &gt; &gt;   my_string ms(&quot;foo&quot;); // D<br>
&gt; &gt; &gt; &gt; &gt; }<br>
&gt; &gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt; We never warn for a class that is in category (1). my_lock \
would be<br> &gt; &gt; &gt; &gt; &gt; in category (2), so we warn on A but not B. \
my_string would be in<br> &gt; &gt; &gt; &gt; &gt; category (3), so we warn on both C \
and D.<br> &gt; &gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt; Which of these does the warn_unused attribute model?<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt;  It doesn&#39;t model anything. It prevents disabling of the<br>
&gt; &gt; &gt; &gt; unused-variable warning for whatever type that has the \
attribute.<br> &gt; &gt; &gt;<br>
&gt; &gt; &gt; So which of the above behaviors do you get? (Or do you get \
something<br> &gt; &gt; &gt; else?)<br>
&gt; &gt;<br>
&gt; &gt;  I think you are talking about something slightly different. This is<br>
&gt; &gt; about the (-W)unused-variable warning. So A and C obviously don&#39;t \
apply.<br> &gt;<br>
&gt;  But since you ask, without looking at the code, presumably<br>
&gt; (-W)unused-result has code similar to unused-variable that also disables<br>
&gt; the warning if the type in question has non-trivial ctor/dtor, so you could<br>
&gt; do a similar modification there to enable the warning for types with<br>
&gt; warn_unused attribute.<br>
<br>
</div></div> The attached patch adds this functionality for the -Wunused-value \
warning.<br> <span class="HOEnZb"><font color="#888888"><br>
--<br>
 Lubos Lunak<br>
 <a href="mailto:l.lunak@suse.cz">l.lunak@suse.cz</a><br>
</font></span></blockquote></div><br>



_______________________________________________
cfe-commits mailing list
cfe-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic