mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-16 22:26:37 +00:00

Calling a pure virtual method during construction or destruction is undefined behavior. It's worth it to warn about it by default. That part is now known as the cplusplus.PureVirtualCall checker. Calling a normal virtual method during construction or destruction may be fine, but does behave unexpectedly, as it skips virtual dispatch. Do not warn about this by default, but let projects opt in into it by enabling the optin.cplusplus.VirtualCall checker manually. Give the two parts differentiated warning text: Before: Call to virtual function during construction or destruction: Call to pure virtual function during construction Call to virtual function during construction or destruction: Call to virtual function during destruction After: Pure virtual method call: Call to pure virtual method 'X::foo' during construction has undefined behavior Unexpected loss of virtual dispatch: Call to virtual method 'Y::bar' during construction bypasses virtual dispatch Also fix checker names in consumers that support them (eg., clang-tidy) because we now have different checker names for pure virtual calls and regular virtual calls. Also fix capitalization in the bug category. Differential Revision: https://reviews.llvm.org/D64274 llvm-svn: 369449
10 lines
200 B
C++
10 lines
200 B
C++
namespace header {
|
|
class Z {
|
|
public:
|
|
Z() {
|
|
foo(); // impure-warning {{Call to virtual method 'Z::foo' during construction bypasses virtual dispatch}}
|
|
}
|
|
virtual int foo();
|
|
};
|
|
}
|