diff options
| author | David Bolvansky <david.bolvansky@gmail.com> | 2019-08-31 18:31:19 +0000 |
|---|---|---|
| committer | David Bolvansky <david.bolvansky@gmail.com> | 2019-08-31 18:31:19 +0000 |
| commit | d533f69aa9700f6c421ed2b8cde12bdc22ee6529 (patch) | |
| tree | 124f76f6fc705dd7459d36897eab9879a23e1c20 /clang/test | |
| parent | ff0ad3c43d44e36d20787cfe1b4e4404de4c7cff (diff) | |
| download | bcm5719-llvm-d533f69aa9700f6c421ed2b8cde12bdc22ee6529.tar.gz bcm5719-llvm-d533f69aa9700f6c421ed2b8cde12bdc22ee6529.zip | |
[clang] Warning for non-final classes with final destructors
Marking a class' destructor final prevents the class from being inherited from. However, it is a subtle and awkward way to express that at best, and unintended at worst. It may also generate worse code (in other compilers) than marking the class itself final. For these reasons, this revision adds a warning for nonfinal classes with final destructors, with a note to suggest marking the class final to silence the warning.
See https://reviews.llvm.org/D66621 for more background.
Patch by logan-5 (Logan Smith)
Differential Revision: https://reviews.llvm.org/D66711
llvm-svn: 370594
Diffstat (limited to 'clang/test')
| -rw-r--r-- | clang/test/SemaCXX/MicrosoftExtensions.cpp | 5 | ||||
| -rw-r--r-- | clang/test/SemaCXX/warn-final-dtor-non-final-class.cpp | 13 |
2 files changed, 18 insertions, 0 deletions
diff --git a/clang/test/SemaCXX/MicrosoftExtensions.cpp b/clang/test/SemaCXX/MicrosoftExtensions.cpp index cc6ac96aca9..4dca1b61342 100644 --- a/clang/test/SemaCXX/MicrosoftExtensions.cpp +++ b/clang/test/SemaCXX/MicrosoftExtensions.cpp @@ -440,6 +440,11 @@ struct SealedType sealed : SomeBase { // expected-error@+1 {{base 'SealedType' is marked 'sealed'}} struct InheritFromSealed : SealedType {}; +class SealedDestructor { // expected-note {{mark 'SealedDestructor' as 'sealed' to silence this warning}} + // expected-warning@+1 {{'sealed' keyword is a Microsoft extension}} + virtual ~SealedDestructor() sealed; // expected-warning {{class with destructor marked 'sealed' cannot be inherited from}} +}; + void AfterClassBody() { // expected-warning@+1 {{attribute 'deprecated' is ignored, place it after "struct" to apply attribute to type declaration}} struct D {} __declspec(deprecated); diff --git a/clang/test/SemaCXX/warn-final-dtor-non-final-class.cpp b/clang/test/SemaCXX/warn-final-dtor-non-final-class.cpp new file mode 100644 index 00000000000..32961c2c7fd --- /dev/null +++ b/clang/test/SemaCXX/warn-final-dtor-non-final-class.cpp @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s -Wfinal-dtor-non-final-class + +class A { + ~A(); +}; + +class B { // expected-note {{mark 'B' as 'final' to silence this warning}} + virtual ~B() final; // expected-warning {{class with destructor marked 'final' cannot be inherited from}} +}; + +class C final { + virtual ~C() final; +}; |

