[LLVMbugs] [Bug 10513] New: Virtual functions called from constructors/destructors should cause warning

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Jul 27 08:44:22 PDT 2011


http://llvm.org/bugs/show_bug.cgi?id=10513

           Summary: Virtual functions called from constructors/destructors
                    should cause warning
           Product: clang
           Version: trunk
          Platform: Other
        OS/Version: FreeBSD
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: yuri at tsoft.com
                CC: llvmbugs at cs.uiuc.edu, dgregor at apple.com


I would like to suggest that clang issues a warning 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.

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 clang can prevent many errors waiting to happen from
happening. gcc must do as much as possible preventing dangerous coding
patterns.

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list