This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C++] Weffc++/Wnon-virtual-dtor confusion
- From: Markus Trippelsdorf <markus at trippelsdorf dot de>
- To: Nathan Sidwell <nathan at acm dot org>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>, Jason Merrill <jason at redhat dot com>
- Date: Fri, 4 Apr 2014 19:23:50 +0200
- Subject: Re: [C++] Weffc++/Wnon-virtual-dtor confusion
- Authentication-results: sourceware.org; auth=none
- References: <533967BE dot 1020301 at acm dot org> <20140404163809 dot GA285 at x4> <533EE25D dot 9090406 at acm dot org> <20140404165430 dot GB285 at x4> <533EE635 dot 4090106 at acm dot org>
On 2014.04.04 at 18:04 +0100, Nathan Sidwell wrote:
> On 04/04/14 17:54, Markus Trippelsdorf wrote:
>
> > markus@x4 tmp % g++ -Wnon-virtual-dtor -std=c++11 -c test.ii
> > test.ii: In instantiation of âclass A<>â:
> > test.ii:12:16: required from here
> > test.ii:9:26: warning: base class âclass opt_storage<0>â has accessible non-virtual destructor [-Wnon-virtual-dtor]
> > template <int = 0> class A : Option, opt_storage<0>
>
> ah, you've hit on the one case I was unsure about -- IMHO Scott's rule about
> bases is incomplete. The rule should be for publicly accessible bases only --
> opt_storage is private.
>
> The aim of the rule is to make sure that random code doing:
>
> A_Base_type *ptr = ptr_to_derived; // implicit base cast
> ...
> delete ptr;
>
> behaved as one might expect and invoke the final polymorphic dtor. Such an
> implicit cast to a private base can't happen outside of the class. Inside the
> class one's expected to know what one's doing.
>
> I'm fine with adding a TREE_PUBLIC (base_binfo) check into the loop in c_b_a_m.
> Would that work for you?
Yes. Thanks.
--
Markus