Skip to content

Commit c50da3d

Browse files
committedSep 3, 2019
Added fixit notes for -Wfinal-dtor-non-final-class
llvm-svn: 370737
1 parent 25d5b54 commit c50da3d

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed
 

‎clang/lib/Sema/SemaDeclCXX.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -6241,10 +6241,14 @@ void Sema::CheckCompletedCXXClass(CXXRecordDecl *Record) {
62416241
if (const CXXDestructorDecl *dtor = Record->getDestructor()) {
62426242
if (const FinalAttr *FA = dtor->getAttr<FinalAttr>()) {
62436243
Diag(FA->getLocation(), diag::warn_final_dtor_non_final_class)
6244-
<< FA->isSpelledAsSealed();
6245-
Diag(Record->getLocation(), diag::note_final_dtor_non_final_class_silence)
6246-
<< Context.getRecordType(Record)
6247-
<< FA->isSpelledAsSealed();
6244+
<< FA->isSpelledAsSealed()
6245+
<< FixItHint::CreateRemoval(FA->getLocation())
6246+
<< FixItHint::CreateInsertion(
6247+
getLocForEndOfToken(Record->getLocation()),
6248+
(FA->isSpelledAsSealed() ? " sealed" : " final"));
6249+
Diag(Record->getLocation(),
6250+
diag::note_final_dtor_non_final_class_silence)
6251+
<< Context.getRecordType(Record) << FA->isSpelledAsSealed();
62486252
}
62496253
}
62506254
}

‎clang/test/SemaCXX/warn-final-dtor-non-final-class.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s -Wfinal-dtor-non-final-class
2+
// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -Wfinal-dtor-non-final-class -fdiagnostics-parseable-fixits 2>&1 | FileCheck %s
23

34
class A {
45
~A();
56
};
67

78
class B { // expected-note {{mark 'B' as 'final' to silence this warning}}
9+
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:8-[[@LINE-1]]:8}:" final"
810
virtual ~B() final; // expected-warning {{class with destructor marked 'final' cannot be inherited from}}
11+
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:18-[[@LINE-1]]:23}:""
912
};
1013

1114
class C final {

0 commit comments

Comments
 (0)
Please sign in to comment.