thakis created this revision.

r312167 made it so that we emit Wdelete-non-virtual-dtor from `delete` 
statements that are in system headers (e.g. std::unique_ptr). That works great 
on Linux and macOS, but on Windows there are non-final classes that are defined 
in system headers that have virtual methods but non-virtual destructors and yet 
get deleted through a base class pointer (e.g. ATL::CAccessToken::CRevert). So 
paddle back a bit and don't emit the warning if it's about a class defined in a 
system header.


https://reviews.llvm.org/D37324

Files:
  lib/Sema/SemaExprCXX.cpp
  test/SemaCXX/destructor.cpp


Index: lib/Sema/SemaExprCXX.cpp
===================================================================
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -3299,6 +3299,12 @@
   if (!PointeeRD->isPolymorphic() || PointeeRD->hasAttr<FinalAttr>())
     return;
 
+  // If the superclass is in a system header, there's nothing that can be done.
+  // The `delete` (where we emit the warning) can be in a system header,
+  // what matters for this warning is where the deleted type is defined.
+  if (getSourceManager().isInSystemHeaer(PointeeRD->getLocation()))
+    return;
+
   QualType ClassType = dtor->getThisType(Context)->getPointeeType();
   if (PointeeRD->isAbstract()) {
     // If the class is abstract, we warn by default, because we're
Index: test/SemaCXX/destructor.cpp
===================================================================
--- test/SemaCXX/destructor.cpp
+++ test/SemaCXX/destructor.cpp
@@ -8,6 +8,11 @@
 
 #pragma clang system_header
 namespace dnvd {
+
+struct SystemB {
+  virtual void foo();
+};
+
 template <typename T>
 class simple_ptr {
 public:
@@ -399,6 +404,11 @@
     simple_ptr<VF> vf(new VF());
     use(*vf);
   }
+  {
+    simple_ptr<SystemB> sb(new SystemB());
+    use(*sb);
+  }
+
 }
 
 void warn1() {


Index: lib/Sema/SemaExprCXX.cpp
===================================================================
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -3299,6 +3299,12 @@
   if (!PointeeRD->isPolymorphic() || PointeeRD->hasAttr<FinalAttr>())
     return;
 
+  // If the superclass is in a system header, there's nothing that can be done.
+  // The `delete` (where we emit the warning) can be in a system header,
+  // what matters for this warning is where the deleted type is defined.
+  if (getSourceManager().isInSystemHeaer(PointeeRD->getLocation()))
+    return;
+
   QualType ClassType = dtor->getThisType(Context)->getPointeeType();
   if (PointeeRD->isAbstract()) {
     // If the class is abstract, we warn by default, because we're
Index: test/SemaCXX/destructor.cpp
===================================================================
--- test/SemaCXX/destructor.cpp
+++ test/SemaCXX/destructor.cpp
@@ -8,6 +8,11 @@
 
 #pragma clang system_header
 namespace dnvd {
+
+struct SystemB {
+  virtual void foo();
+};
+
 template <typename T>
 class simple_ptr {
 public:
@@ -399,6 +404,11 @@
     simple_ptr<VF> vf(new VF());
     use(*vf);
   }
+  {
+    simple_ptr<SystemB> sb(new SystemB());
+    use(*sb);
+  }
+
 }
 
 void warn1() {
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to