r312216 - Suppress -Wdelete-non-virtual-dtor warnings about classes defined in system headers.

Nico Weber via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 30 23:17:08 PDT 2017


Author: nico
Date: Wed Aug 30 23:17:08 2017
New Revision: 312216

URL: http://llvm.org/viewvc/llvm-project?rev=312216&view=rev
Log:
Suppress -Wdelete-non-virtual-dtor warnings about classes defined in system headers.

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

Modified:
    cfe/trunk/lib/Sema/SemaExprCXX.cpp
    cfe/trunk/test/SemaCXX/destructor.cpp

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=312216&r1=312215&r2=312216&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Wed Aug 30 23:17:08 2017
@@ -3299,6 +3299,12 @@ void Sema::CheckVirtualDtorCall(CXXDestr
   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().isInSystemHeader(PointeeRD->getLocation()))
+    return;
+
   QualType ClassType = dtor->getThisType(Context)->getPointeeType();
   if (PointeeRD->isAbstract()) {
     // If the class is abstract, we warn by default, because we're

Modified: cfe/trunk/test/SemaCXX/destructor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/destructor.cpp?rev=312216&r1=312215&r2=312216&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/destructor.cpp (original)
+++ cfe/trunk/test/SemaCXX/destructor.cpp Wed Aug 30 23:17:08 2017
@@ -8,6 +8,11 @@
 
 #pragma clang system_header
 namespace dnvd {
+
+struct SystemB {
+  virtual void foo();
+};
+
 template <typename T>
 class simple_ptr {
 public:
@@ -249,6 +254,7 @@ private:
 };
 
 void use(B&);
+void use(SystemB&);
 void use(VB&);
 
 void nowarnstack() {
@@ -399,6 +405,11 @@ void nowarn1() {
     simple_ptr<VF> vf(new VF());
     use(*vf);
   }
+  {
+    simple_ptr<SystemB> sb(new SystemB());
+    use(*sb);
+  }
+
 }
 
 void warn1() {




More information about the cfe-commits mailing list