[PATCH] Don't emit exit-time destructor warnings for trivial explicitly defaulted dtors
Stephan Tolksdorf
st at quanttec.com
Thu Mar 27 12:59:02 PDT 2014
Hi rsmith,
This commit also adds an additional test case for the global destructor warning.
http://llvm-reviews.chandlerc.com/D3205
Files:
lib/Sema/SemaDeclCXX.cpp
test/SemaCXX/warn-exit-time-destructors.cpp
test/SemaCXX/warn-global-constructors.cpp
Index: lib/Sema/SemaDeclCXX.cpp
===================================================================
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -10463,14 +10463,15 @@
<< VD->getType());
DiagnoseUseOfDecl(Destructor, VD->getLocation());
+ if (Destructor->isTrivial()) return;
if (!VD->hasGlobalStorage()) return;
// Emit warning for non-trivial dtor in global scope (a real global,
// class-static, function-static).
Diag(VD->getLocation(), diag::warn_exit_time_destructor);
// TODO: this should be re-enabled for static locals by !CXAAtExit
- if (!Destructor->isTrivial() && !VD->isStaticLocal())
+ if (!VD->isStaticLocal())
Diag(VD->getLocation(), diag::warn_global_destructor);
}
Index: test/SemaCXX/warn-exit-time-destructors.cpp
===================================================================
--- test/SemaCXX/warn-exit-time-destructors.cpp
+++ test/SemaCXX/warn-exit-time-destructors.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -Wexit-time-destructors %s -verify
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -Wexit-time-destructors %s -verify
namespace test1 {
struct A { ~A(); };
@@ -23,5 +23,23 @@
static A &e = b[5];
static A &f = c[5][7];
}
+}
+
+namespace test3 {
+ struct A { ~A() = default; };
+ A a;
+
+ struct B { ~B(); };
+ struct C : B { ~C() = default; };
+ C c; // expected-warning {{exit-time destructor}}
+ class D {
+ friend struct E;
+ ~D() = default;
+ };
+ struct E : D {
+ D d;
+ ~E() = default;
+ };
+ E e;
}
Index: test/SemaCXX/warn-global-constructors.cpp
===================================================================
--- test/SemaCXX/warn-global-constructors.cpp
+++ test/SemaCXX/warn-global-constructors.cpp
@@ -105,7 +105,18 @@
namespace pr19253 {
struct A { ~A() = default; };
A a;
- struct B { ~B() {} };
+
+ struct B { ~B(); };
struct C : B { ~C() = default; };
C c; // expected-warning {{global destructor}}
+
+ class D {
+ friend struct E;
+ ~D() = default;
+ };
+ struct E : D {
+ D d;
+ ~E() = default;
+ };
+ E e;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D3205.1.patch
Type: text/x-patch
Size: 2123 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140327/ff4058e0/attachment.bin>
More information about the cfe-commits
mailing list