Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Virtual functions called from constructors/destructors should cause warning #10782

Open Quuxplusone opened 13 years ago

Quuxplusone commented 13 years ago
Bugzilla Link PR10513
Status NEW
Importance P normal
Reported by Yuri (yuri@tsoft.com)
Reported on 2011-07-27 10:44:21 -0700
Last modified on 2014-04-11 18:27:41 -0700
Version trunk
Hardware Other FreeBSD
CC dgregor@apple.com, geoff@geoffhill.org, llvm-bugs@lists.llvm.org, zinenko+llvmbug@google.com
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
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.
Quuxplusone commented 13 years ago

This seems like a reasonable warning request

Quuxplusone commented 10 years ago

Seems like this functionality already exists, starting with r147494, as the alpha.cplusplus.VirtualCall analyze checker.

http://llvm.org/viewvc/llvm-project?view=revision&revision=147494