public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "mlg7 at yandex dot ru" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/47940] New: can call a pure virtual from a constructor/destructor Date: Tue, 01 Mar 2011 10:10:00 -0000 [thread overview] Message-ID: <bug-47940-4@http.gcc.gnu.org/bugzilla/> (raw) http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47940 Summary: can call a pure virtual from a constructor/destructor Product: gcc Version: 4.4.5 Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: c++ AssignedTo: unassigned@gcc.gnu.org ReportedBy: mlg7@yandex.ru A colleague of mine have been examining a crash that boils down to the following: --hellobug.cpp-- class Base { public: Base() { usefunc(); } virtual void func()=0; void usefunc() { func(); } }; class Derived: public Base { public: virtual void func() {} }; int main() { Derived d; return 0; } --eof-- $ g++ -Wall -Wextra hellobug.cpp {just nothing} $ ./a.out pure virtual method called terminate called without an active exception Aborted That is, "you asked for it, you got it" [1]. == [1] from "Real Programmers Don't" == A variation: ==byebug.cpp== #include <stdio.h> class Base { public: ~Base() { usefunc(); } virtual void func()=0; void usefunc() { func(); } }; class Derived: public Base { public: virtual void func() {} }; int main() { Derived d; printf("life is good\n"); return 0; } ==eof== $ g++ -Wall -Wextra byebug.cpp {again nothing} $ ./a.out life is good pure virtual method called terminate called without an active exception Aborted I have to note that in a big software project, the mistake is not so obvious. But what can be done? Functions that call pure virtual functions cannot be called from constructors and destructors. This may be discovered at compile-time, and the above text makes a good error/warning message. WHAT I GET: no warning WHAT I WOULD EXPECT: a warning or an error message: "Functions that call pure virtual functions cannot be called from constructors and destructors" $ gcc -v Using built-in specs. Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.4.4-14ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.4 --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 4.4.5 (Ubuntu/Linaro 4.4.4-14ubuntu5)
next reply other threads:[~2011-03-01 10:10 UTC|newest] Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top 2011-03-01 10:10 mlg7 at yandex dot ru [this message] 2011-03-01 10:14 ` [Bug c++/47940] " pinskia at gcc dot gnu.org 2011-03-01 11:34 ` mlg7 at yandex dot ru 2011-03-01 12:19 ` [Bug c++/47940] warn about calls to " redi at gcc dot gnu.org 2011-03-01 12:30 ` redi at gcc dot gnu.org 2011-03-01 12:32 ` redi at gcc dot gnu.org 2011-03-01 17:23 ` mlg7 at yandex dot ru 2024-06-11 14:31 ` pinskia at gcc dot gnu.org 2024-06-11 14:32 ` [Bug c++/47940] warn about calls to a pure virtual indirectly " pinskia at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-47940-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).