r186793 - report unused-value warning also for warn_unused types
Lubos Lunak
l.lunak at suse.cz
Sun Jul 21 06:15:59 PDT 2013
Author: llunak
Date: Sun Jul 21 08:15:58 2013
New Revision: 186793
URL: http://llvm.org/viewvc/llvm-project?rev=186793&view=rev
Log:
report unused-value warning also for warn_unused types
Modified:
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/test/SemaCXX/warn-unused-value.cpp
Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=186793&r1=186792&r2=186793&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Sun Jul 21 08:15:58 2013
@@ -2075,8 +2075,17 @@ bool Expr::isUnusedResultAWarning(const
return false;
case CXXTemporaryObjectExprClass:
- case CXXConstructExprClass:
+ case CXXConstructExprClass: {
+ if (const CXXRecordDecl *Type = getType()->getAsCXXRecordDecl()) {
+ if (Type->hasAttr<WarnUnusedAttr>()) {
+ WarnE = this;
+ Loc = getLocStart();
+ R1 = getSourceRange();
+ return true;
+ }
+ }
return false;
+ }
case ObjCMessageExprClass: {
const ObjCMessageExpr *ME = cast<ObjCMessageExpr>(this);
Modified: cfe/trunk/test/SemaCXX/warn-unused-value.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-unused-value.cpp?rev=186793&r1=186792&r2=186793&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-unused-value.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-unused-value.cpp Sun Jul 21 08:15:58 2013
@@ -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}}
+}
+}
More information about the cfe-commits
mailing list