public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/33475]  New: New warning suggestion: virtual functions called from constructors/destructors
@ 2007-09-18 17:50 yuri at tsoft dot com
  2007-09-18 18:41 ` [Bug c++/33475] " bangerth at dealii dot org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: yuri at tsoft dot com @ 2007-09-18 17:50 UTC (permalink / raw)
  To: gcc-bugs

I would like to suggest that gcc issues a warning (with -Wall) when any virtual
functions are called from constructors and destructors of these objects.

During construtors and destructors derived objects aren't complete and almost
always virtual functions would be called on undefined derived classes.


-- 
           Summary: New warning suggestion: virtual functions called from
                    constructors/destructors
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: yuri at tsoft dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33475


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/33475] New warning suggestion: virtual functions called from constructors/destructors
  2007-09-18 17:50 [Bug c++/33475] New: New warning suggestion: virtual functions called from constructors/destructors yuri at tsoft dot com
@ 2007-09-18 18:41 ` bangerth at dealii dot org
  2007-09-18 18:42 ` bangerth at dealii dot org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: bangerth at dealii dot org @ 2007-09-18 18:41 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from bangerth at dealii dot org  2007-09-18 18:41 -------
*** Bug 33476 has been marked as a duplicate of this bug. ***


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33475


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/33475] New warning suggestion: virtual functions called from constructors/destructors
  2007-09-18 17:50 [Bug c++/33475] New: New warning suggestion: virtual functions called from constructors/destructors yuri at tsoft dot com
  2007-09-18 18:41 ` [Bug c++/33475] " bangerth at dealii dot org
@ 2007-09-18 18:42 ` bangerth at dealii dot org
  2007-09-18 19:04 ` pcarlini at suse dot de
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: bangerth at dealii dot org @ 2007-09-18 18:42 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from bangerth at dealii dot org  2007-09-18 18:41 -------
*** Bug 33477 has been marked as a duplicate of this bug. ***


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33475


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/33475] New warning suggestion: virtual functions called from constructors/destructors
  2007-09-18 17:50 [Bug c++/33475] New: New warning suggestion: virtual functions called from constructors/destructors yuri at tsoft dot com
  2007-09-18 18:41 ` [Bug c++/33475] " bangerth at dealii dot org
  2007-09-18 18:42 ` bangerth at dealii dot org
@ 2007-09-18 19:04 ` pcarlini at suse dot de
  2007-09-18 19:05 ` pcarlini at suse dot de
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pcarlini at suse dot de @ 2007-09-18 19:04 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from pcarlini at suse dot de  2007-09-18 19:04 -------
*** Bug 33481 has been marked as a duplicate of this bug. ***


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33475


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/33475] New warning suggestion: virtual functions called from constructors/destructors
  2007-09-18 17:50 [Bug c++/33475] New: New warning suggestion: virtual functions called from constructors/destructors yuri at tsoft dot com
                   ` (2 preceding siblings ...)
  2007-09-18 19:04 ` pcarlini at suse dot de
@ 2007-09-18 19:05 ` pcarlini at suse dot de
  2007-09-19 23:37 ` yuri at tsoft dot com
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pcarlini at suse dot de @ 2007-09-18 19:05 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from pcarlini at suse dot de  2007-09-18 19:04 -------
*** Bug 33480 has been marked as a duplicate of this bug. ***


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33475


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/33475] New warning suggestion: virtual functions called from constructors/destructors
  2007-09-18 17:50 [Bug c++/33475] New: New warning suggestion: virtual functions called from constructors/destructors yuri at tsoft dot com
                   ` (3 preceding siblings ...)
  2007-09-18 19:05 ` pcarlini at suse dot de
@ 2007-09-19 23:37 ` yuri at tsoft dot com
  2009-01-21  1:38 ` gcc at eseidel dot com
  2010-04-29 22:36 ` redi at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: yuri at tsoft dot com @ 2007-09-19 23:37 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from yuri at tsoft dot com  2007-09-19 23:37 -------
I would like to note that this isn't a clear-cut suggestion for the following
reasons:
* It's impossible to enforce such warning in all cases, only in case of virtual
functions immediately called from constructor/destructor.
* People often use virtual functions from destructors to uninitialize things.
And in many cases it's semi-safe. But it's almost always wrong to call virtual
functions from constructors.
* It probably makes sense to add such warning to Valgrind as well to issue it
based on the run-time analysis

But still such warning in gcc can prevent many errors waiting to happen from
happening. gcc must do as much as possible preventing dangerous coding
patterns.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33475


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/33475] New warning suggestion: virtual functions called from constructors/destructors
  2007-09-18 17:50 [Bug c++/33475] New: New warning suggestion: virtual functions called from constructors/destructors yuri at tsoft dot com
                   ` (4 preceding siblings ...)
  2007-09-19 23:37 ` yuri at tsoft dot com
@ 2009-01-21  1:38 ` gcc at eseidel dot com
  2010-04-29 22:36 ` redi at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: gcc at eseidel dot com @ 2009-01-21  1:38 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from gcc at eseidel dot com  2009-01-21 01:38 -------
We just hit this when hacking on Chromium code.  We were calling a virtual
function from a constructor (unintentionally) and the bug was that GCC was
silently calling the base-class implementation.  After consulting the web, it
seems this is correct behavior.  It would have ben nice if GCC had warned when
compiling the constructor function that the virtual call would not have worked
"as naively suspected".

Thanks!


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33475


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/33475] New warning suggestion: virtual functions called from constructors/destructors
  2007-09-18 17:50 [Bug c++/33475] New: New warning suggestion: virtual functions called from constructors/destructors yuri at tsoft dot com
                   ` (5 preceding siblings ...)
  2009-01-21  1:38 ` gcc at eseidel dot com
@ 2010-04-29 22:36 ` redi at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu dot org @ 2010-04-29 22:36 UTC (permalink / raw)
  To: gcc-bugs



-- 

redi at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
           Keywords|                            |diagnostic


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33475


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2010-04-29 22:36 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-09-18 17:50 [Bug c++/33475] New: New warning suggestion: virtual functions called from constructors/destructors yuri at tsoft dot com
2007-09-18 18:41 ` [Bug c++/33475] " bangerth at dealii dot org
2007-09-18 18:42 ` bangerth at dealii dot org
2007-09-18 19:04 ` pcarlini at suse dot de
2007-09-18 19:05 ` pcarlini at suse dot de
2007-09-19 23:37 ` yuri at tsoft dot com
2009-01-21  1:38 ` gcc at eseidel dot com
2010-04-29 22:36 ` redi at gcc dot gnu dot org

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).