From: David Blaikie Date: Wed, 24 Oct 2012 21:29:06 +0000 (+0000) Subject: Fix false positive in -Wunused-variable when a ctor call make involve cleanups. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=39e177692ea2096af2ad0dcead79250b50958fa3;p=clang 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 --- 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(Init)) + Init = Cleanups->getSubExpr(); const CXXConstructExpr *Construct = dyn_cast(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())); + } +}