[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: Lubos Lunak <l.lunak () suse ! cz>
Date: 2013-07-20 23:24:11
Message-ID: 201307210124.11079.l.lunak () suse ! cz
[Download RAW message or body]
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
["0001-report-unused-value-warning-also-for-warn_unused-typ.patch" (text/x-diff)]
From 0e46fa636b24a9e3e17f99d6d6b440da61b61971 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lubo=C5=A1=20Lu=C5=88=C3=A1k?= <l.lunak@suse.cz>
Date: Sun, 21 Jul 2013 01:08:27 +0200
Subject: [PATCH] report unused-value warning also for warn_unused types
---
lib/AST/Expr.cpp | 13 ++++++++++++-
test/SemaCXX/warn-unused-value.cpp | 20 ++++++++++++++++++++
2 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp
index c4be32e..b3bb3f7 100644
--- a/lib/AST/Expr.cpp
+++ b/lib/AST/Expr.cpp
@@ -2072,8 +2072,19 @@ bool Expr::isUnusedResultAWarning(const Expr *&WarnE, SourceLocation &Loc,
return false;
case CXXTemporaryObjectExprClass:
- case CXXConstructExprClass:
+ case CXXConstructExprClass: {
+ QualType Ty = getType();
+ if (const TagType *TT = Ty->getAs<TagType>()) {
+ const TagDecl *Tag = TT->getDecl();
+ if (Tag->hasAttr<WarnUnusedAttr>()) {
+ WarnE = this;
+ Loc = getLocStart();
+ R1 = getSourceRange();
+ return true;
+ }
+ }
return false;
+ }
case ObjCMessageExprClass: {
const ObjCMessageExpr *ME = cast<ObjCMessageExpr>(this);
diff --git a/test/SemaCXX/warn-unused-value.cpp b/test/SemaCXX/warn-unused-value.cpp
index 072ee60..5e43d3e 100644
--- a/test/SemaCXX/warn-unused-value.cpp
+++ b/test/SemaCXX/warn-unused-value.cpp
@@ -49,3 +49,23 @@ namespace test2 {
}
}
+namespace test3 {
+struct Used {
+ Used();
+ Used(int);
+ Used(int, int);
+};
+struct __attribute__((warn_unused)) Unused {
+ Unused();
+ Unused(int);
+ Unused(int, int);
+};
+void f() {
+ Used();
+ Used(1);
+ Used(1, 1);
+ Unused(); // expected-warning {{expression result unused}}
+ Unused(1); // expected-warning {{expression result unused}}
+ Unused(1, 1); // expected-warning {{expression result unused}}
+}
+}
--
1.8.1.4
_______________________________________________
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