From b13091dd9dbabe7fde4b112c4bfb9be729493c16 Mon Sep 17 00:00:00 2001 From: Tobias Burnus Date: Fri, 11 Jan 2019 20:40:13 +0100 Subject: [PATCH] PR C++/88114 Gen destructor of an abstract class PR C++/8811 * decl2.c (maybe_emit_vtables): If needed, generate code for the destructor of an abstract class. (mark_used): Update comment for older function-name change. PR C++/88114 * g++.dg/cpp0x/defaulted61.C: New. * g++.dg/cpp0x/defaulted62.C: New. From-SVN: r267855 --- gcc/cp/ChangeLog | 7 +++++++ gcc/cp/decl2.c | 12 +++++++++++- gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/g++.dg/cpp0x/defaulted61.C | 22 +++++++++++++++++++++ gcc/testsuite/g++.dg/cpp0x/defaulted62.C | 25 ++++++++++++++++++++++++ 5 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/defaulted61.C create mode 100644 gcc/testsuite/g++.dg/cpp0x/defaulted62.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 4b9fa821d74..5a5256f13fc 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2019-01-11 Tobias Burnus + + PR C++/88114 + * decl2.c (maybe_emit_vtables): If needed, generate code for + the destructor of an abstract class. + (mark_used): Update comment for older function-name change. + 2019-01-11 Paolo Carlini * decl.c (start_decl): Improve error location. diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index dbab95fbc96..591cc21be20 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -2220,6 +2220,16 @@ maybe_emit_vtables (tree ctype) } } + /* For abstract classes, the destructor has been removed from the + vtable (in class.c's build_vtbl_initializer). For a compiler- + generated destructor, it hence might not have been generated in + this translation unit - and with '#pragma interface' it might + never get generated. */ + if (CLASSTYPE_PURE_VIRTUALS (ctype) + && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (ctype) + && DECL_DEFAULTED_IN_CLASS_P(CLASSTYPE_DESTRUCTOR(ctype))) + note_vague_linkage_fn (CLASSTYPE_DESTRUCTOR(ctype)); + /* Since we're writing out the vtable here, also write the debug info. */ note_debug_info_needed (ctype); @@ -5497,7 +5507,7 @@ mark_used (tree decl, tsubst_flags_t complain) within the body of a function so as to avoid collecting live data on the stack (such as overload resolution candidates). - We could just let cp_write_global_declarations handle synthesizing + We could just let c_parse_final_cleanups handle synthesizing this function by adding it to deferred_fns, but doing it at the use site produces better error messages. */ ++function_depth; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3b1de48f990..8a031e1d9f8 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2019-01-11 Tobias Burnus + + PR C++/88114 + * g++.dg/cpp0x/defaulted61.C: New + * g++.dg/cpp0x/defaulted62.C: New. + 2019-01-11 Jakub Jelinek PR tree-optimization/88693 diff --git a/gcc/testsuite/g++.dg/cpp0x/defaulted61.C b/gcc/testsuite/g++.dg/cpp0x/defaulted61.C new file mode 100644 index 00000000000..e7e0a486292 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/defaulted61.C @@ -0,0 +1,22 @@ +// { dg-do compile { target c++11 } } +// { dg-final { scan-assembler "_ZN3OneD0Ev" } } + +// PR C++/88114 +// Destructor of an abstract class was never generated +// when compiling the class - nor later due to the +// '#pragma interface' + +#pragma implementation +#pragma interface + +class One +{ + public: + virtual ~One() = default; + void some_fn(); + virtual void later() = 0; + private: + int m_int; +}; + +void One::some_fn() { } diff --git a/gcc/testsuite/g++.dg/cpp0x/defaulted62.C b/gcc/testsuite/g++.dg/cpp0x/defaulted62.C new file mode 100644 index 00000000000..d8dab608816 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/defaulted62.C @@ -0,0 +1,25 @@ +// { dg-do compile { target c++11 } } +// { dg-final { scan-assembler-not "_ZN3OneD0Ev" } } + +// PR C++/88114 +// Destructor of an abstract class was never generated +// when compiling the class - nor later due to the +// '#pragma interface' +// -> g++.dg/cpp0x/defaulted61.C + +// HERE, in g++.dg/cpp0x/defaulted62.C: +// As we have commented the pragmas, it should NOT be created +// #pragma implementation +// #pragma interface + +class One +{ + public: + virtual ~One() = default; + void some_fn(); + virtual void later() = 0; + private: + int m_int; +}; + +void One::some_fn() { } -- 2.30.2