>Submitter-Id:  net
>Originator:    Cesar Eduardo Barros
>Organization:  
>Confidential:  no
>Synopsis:      -Wnon-virtual-dtor should't complain of protected dtor
>Severity:      non-critical
>Priority:      low
>Category:      c++
>Class:         sw-bug
>Release:       3.1.1 20020703 (Debian prerelease) (Debian testing/unstable)
>Environment:
System: Linux flower 2.4.18-preempt #1 Mon Jun 17 14:21:46 BRT 2002 i686 unknown
Architecture: i686

        
host: i386-pc-linux-gnu
build: i386-pc-linux-gnu
target: i386-pc-linux-gnu
configured with: /mnt/data/gcc-3.1/gcc-3.1-3.1.1ds2/src/configure -v 
--enable-languages=c,c++,java,f77,proto,objc,ada --prefix=/usr 
--mandir=/usr/share/man --infodir=/usr/share/info 
--with-gxx-include-dir=/usr/include/g++-v3-3.1 --enable-shared 
--with-system-zlib --enable-long-long --enable-nls --without-included-gettext 
--enable-clocale=gnu --enable-__cxa_atexit --enable-threads=posix 
--enable-java-gc=boehm --enable-objc-gc i386-linux
>Description:
        -Wnon-virtual-dtor warns even when the destructor is protected and the
        class has only pure virtual members and no friends.

        In that case, there's no way the destructor can be called incorrectly.
        The class can't call it, since there are no methods other than the
        destructor itself. There are no friends who could call it. And if you
        inherit from it without making the derived class' destructor virtual,
        it would complain about it in the derived class, since it has virtual
        functions and a non-virtual destructor (unless it also has no non-pure
        members, no friends and a non-public destructor).
>How-To-Repeat:

Input file:
=== x.cc ===
class x
{
public:
        virtual void y () = 0;

protected:
        ~x () { }
};

void f (x* p)
{
        p->y();
        delete p;
}
======

Command line:
======
g++-3.1 -Wnon-virtual-dtor -O2 -v -save-temps x.cc -o x
======

Compiler output:
======
Reading specs from /usr/lib/gcc-lib/i386-linux/3.1.1/specs
Configured with: /mnt/data/gcc-3.1/gcc-3.1-3.1.1ds2/src/configure -v 
--enable-languages=c,c++,java,f77,proto,objc,ada --prefix=/usr 
--mandir=/usr/share/man --infodir=/usr/share/info 
--with-gxx-include-dir=/usr/include/g++-v3-3.1 --enable-shared 
--with-system-zlib --enable-long-long --enable-nls --without-included-gettext 
--enable-clocale=gnu --enable-__cxa_atexit --enable-threads=posix 
--enable-java-gc=boehm --enable-objc-gc i386-linux
Thread model: posix
gcc version 3.1.1 20020703 (Debian prerelease)
 /usr/lib/gcc-lib/i386-linux/3.1.1/cpp0 -lang-c++ -D__GNUG__=3 -D__DEPRECATED 
-D__EXCEPTIONS -D__GXX_ABI_VERSION=100 -v -D__GNUC__=3 -D__GNUC_MINOR__=1 
-D__GNUC_PATCHLEVEL__=1 -D__ELF__ -Dunix -D__gnu_linux__ -Dlinux -D__ELF__ 
-D__unix__ -D__gnu_linux__ -D__linux__ -D__unix -D__linux -Asystem=posix 
-D__OPTIMIZE__ -D__STDC_HOSTED__=1 -D_GNU_SOURCE -Acpu=i386 -Amachine=i386 
-Di386 -D__i386 -D__i386__ -D__tune_i386__ x.cc -Wnon-virtual-dtor x.ii
GNU CPP version 3.1.1 20020703 (Debian prerelease) (cpplib) (i386 Linux/ELF)
ignoring nonexistent directory "/usr/i386-linux/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/g++-v3-3.1
 /usr/include/g++-v3-3.1/i386-linux
 /usr/include/g++-v3-3.1/backward
 /usr/local/include
 /usr/lib/gcc-lib/i386-linux/3.1.1/include
 /usr/include
End of search list.
 /usr/lib/gcc-lib/i386-linux/3.1.1/cc1plus -fpreprocessed x.ii -quiet -dumpbase 
x.cc -O2 -Wnon-virtual-dtor -version -o x.s
GNU CPP version 3.1.1 20020703 (Debian prerelease) (cpplib) (i386 Linux/ELF)
GNU C++ version 3.1.1 20020703 (Debian prerelease) (i386-linux)
        compiled by GNU C version 3.1.1 20020703 (Debian prerelease).
x.cc:2: warning: `class x' has virtual functions but non-virtual destructor
x.cc: In function `void f(x*)':
x.cc:7: `x::~x()' is protected
x.cc:13: within this context
======

The warning at line 2 is the bogus one. The error at line 13 is on purpose, to
show you can't delete it (and so that the warning is bogus).

>Fix:
        If a class has only pure virtual members besides the destructor and
        has no friends, and the destructor is protected or private, then the
        warning shouldn't be shown.


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]


Reply via email to