aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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()));
+ }
+}