]> granicus.if.org Git - clang/commitdiff
Fix false positive in -Wunused-variable when a ctor call make involve cleanups.
authorDavid Blaikie <dblaikie@gmail.com>
Wed, 24 Oct 2012 21:29:06 +0000 (21:29 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Wed, 24 Oct 2012 21:29:06 +0000 (21:29 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@166625 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/SemaCXX/warn-unused-variables.cpp

index 19442b98c1a8fd498fe59b8a5ed2db5b77270e5e..e8d017c09820a62447ee738744a1386521d9b5a2 100644 (file)
@@ -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()) {
index 8bf2560417adedd026eedd31edb2fc00f0058824..4e8d51d319e932373f39fc61819457e16ae23e9e 100644 (file)
@@ -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()));
+  }
+}