r370737 - Added fixit notes for -Wfinal-dtor-non-final-class

David Bolvansky via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 3 03:32:21 PDT 2019


Author: xbolva00
Date: Tue Sep  3 03:32:21 2019
New Revision: 370737

URL: http://llvm.org/viewvc/llvm-project?rev=370737&view=rev
Log:
Added fixit notes for -Wfinal-dtor-non-final-class

Modified:
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp
    cfe/trunk/test/SemaCXX/warn-final-dtor-non-final-class.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=370737&r1=370736&r2=370737&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Tue Sep  3 03:32:21 2019
@@ -6241,10 +6241,14 @@ void Sema::CheckCompletedCXXClass(CXXRec
     if (const CXXDestructorDecl *dtor = Record->getDestructor()) {
       if (const FinalAttr *FA = dtor->getAttr<FinalAttr>()) {
         Diag(FA->getLocation(), diag::warn_final_dtor_non_final_class)
-          << FA->isSpelledAsSealed();
-        Diag(Record->getLocation(), diag::note_final_dtor_non_final_class_silence)
-          << Context.getRecordType(Record)
-          << FA->isSpelledAsSealed();
+            << FA->isSpelledAsSealed()
+            << FixItHint::CreateRemoval(FA->getLocation())
+            << FixItHint::CreateInsertion(
+                   getLocForEndOfToken(Record->getLocation()),
+                   (FA->isSpelledAsSealed() ? " sealed" : " final"));
+        Diag(Record->getLocation(),
+             diag::note_final_dtor_non_final_class_silence)
+            << Context.getRecordType(Record) << FA->isSpelledAsSealed();
       }
     }
   }

Modified: cfe/trunk/test/SemaCXX/warn-final-dtor-non-final-class.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-final-dtor-non-final-class.cpp?rev=370737&r1=370736&r2=370737&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-final-dtor-non-final-class.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-final-dtor-non-final-class.cpp Tue Sep  3 03:32:21 2019
@@ -1,11 +1,14 @@
 // RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s -Wfinal-dtor-non-final-class
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -Wfinal-dtor-non-final-class -fdiagnostics-parseable-fixits 2>&1 | FileCheck %s
 
 class A {
     ~A();
 };
 
 class B { // expected-note {{mark 'B' as 'final' to silence this warning}}
+    // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:8-[[@LINE-1]]:8}:" final"
     virtual ~B() final; // expected-warning {{class with destructor marked 'final' cannot be inherited from}}
+    // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:18-[[@LINE-1]]:23}:""
 };
 
 class C final {




More information about the cfe-commits mailing list