aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Blaikie <dblaikie@gmail.com>2012-10-24 21:29:06 +0000
committerDavid Blaikie <dblaikie@gmail.com>2012-10-24 21:29:06 +0000
commit39e177692ea2096af2ad0dcead79250b50958fa3 (patch)
tree00137791a748ead8e0fd71f5d8bdf3217317fc68
parent9dd686d2be3c3785a089ff12a3d3eb64e9b32dc0 (diff)
Fix false positive in -Wunused-variable when a ctor call make involve cleanups.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@166625 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaDecl.cpp2
-rw-r--r--test/SemaCXX/warn-unused-variables.cpp12
2 files changed, 14 insertions, 0 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 19442b98c1..e8d017c098 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -1286,6 +1286,8 @@ static bool ShouldDiagnoseUnusedDecl(const NamedDecl *D) {
return false;
if (const Expr *Init = VD->getInit()) {
+ if (const ExprWithCleanups *Cleanups = dyn_cast<ExprWithCleanups>(Init))
+ Init = Cleanups->getSubExpr();
const CXXConstructExpr *Construct =
dyn_cast<CXXConstructExpr>(Init);
if (Construct && !Construct->isElidable()) {
diff --git a/test/SemaCXX/warn-unused-variables.cpp b/test/SemaCXX/warn-unused-variables.cpp
index 8bf2560417..4e8d51d319 100644
--- a/test/SemaCXX/warn-unused-variables.cpp
+++ b/test/SemaCXX/warn-unused-variables.cpp
@@ -123,3 +123,15 @@ namespace PR11550 {
S3 z = a; // expected-warning {{unused variable 'z'}}
}
}
+
+namespace ctor_with_cleanups {
+ struct S1 {
+ ~S1();
+ };
+ struct S2 {
+ S2(const S1&);
+ };
+ void func() {
+ S2 s((S1()));
+ }
+}