From: David Bolvansky Date: Tue, 3 Sep 2019 10:32:21 +0000 (+0000) Subject: Added fixit notes for -Wfinal-dtor-non-final-class X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fe4379e243ad90cb8720c5eb5aaba9c5a5dd6402;p=clang Added fixit notes for -Wfinal-dtor-non-final-class git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@370737 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index a5b4eda43c..e2f0aef7bf 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -6241,10 +6241,14 @@ void Sema::CheckCompletedCXXClass(CXXRecordDecl *Record) { if (const CXXDestructorDecl *dtor = Record->getDestructor()) { if (const FinalAttr *FA = dtor->getAttr()) { 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(); } } } diff --git a/test/SemaCXX/warn-final-dtor-non-final-class.cpp b/test/SemaCXX/warn-final-dtor-non-final-class.cpp index 32961c2c7f..fdfe2ee3b4 100644 --- a/test/SemaCXX/warn-final-dtor-non-final-class.cpp +++ b/test/SemaCXX/warn-final-dtor-non-final-class.cpp @@ -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 {