[PATCH] [analyzer][Review request] Improved checker lists.

Антон Ярцев anton.yartsev at gmail.com
Mon May 5 11:35:00 PDT 2014


Substituted the second example with the one that uses a destructor call.
References to sub-objects used after the destructor has been called are the matter of undefbehavior.MemberRefAfterDtor. Reinitialization of an object whose destructor hasn't been called is a good idea for an another checker!
This checker is designed for the particular cases described in C++03 3.8p5, p7 and C++11 3.8p5, p7.

C++11 3.8p5: Before the lifetime of an object has started but after the storage which the object will occupy has been
allocated or, after the lifetime of an object has ended and before the storage which the object occupied is
reused or released, any pointer that refers to the storage location where the object will be or was located
may be used but only in limited ways. For an object under construction or destruction, see 12.7. Otherwise,
such a pointer refers to allocated storage (3.7.4.2), and using the pointer as if the pointer were of type void*,
is well-defined. Such a pointer may be dereferenced but the resulting lvalue may only be used in limited
ways, as described below. The program has undefined behavior if:
— the object will be or was of a class type with a non-trivial destructor and the pointer is used as the
operand of a delete-expression,
— the pointer is used to access a non-static data member or call a non-static member function of the
object, or
— the pointer is implicitly converted (4.10) to a pointer to a base class type, or
— the pointer is used as the operand of a static_cast (5.2.9) (except when the conversion is to void*,
or to void* and subsequently to char*, or unsigned char*), or
— the pointer is used as the operand of a dynamic_cast (5.2.7). [ Example:
#include <cstdlib>
struct B {
virtual void f();
void mutate();
virtual ~B();
};
struct D1 : B { void f(); };
struct D2 : B { void f(); };
void B::mutate() {
new (this) D2; // reuses storage — ends the lifetime of *this
f(); // undefined behavior
... = this; // OK, this points to valid memory
}
void g() {
void* p = std::malloc(sizeof(D1) + sizeof(D2));
B* pb = new (p) D1;
pb->mutate();
&pb; // OK: pb points to valid memory
void* q = pb; // OK: pb points to valid memory
pb->f(); // undefined behavior, lifetime of *pb has ended
}

http://reviews.llvm.org/D3457

Files:
  www/analyzer/alpha_checks.html
  www/analyzer/available_checks.html
  www/analyzer/checker_dev_manual.html
  www/analyzer/content.css
  www/analyzer/implicit_checks.html
  www/analyzer/potential_checkers.html
  www/analyzer/scripts/expandcollapse.js
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D3457.9083.patch
Type: text/x-patch
Size: 46168 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140505/2c6ceaef/attachment.bin>


More information about the cfe-commits mailing list