
...
Similarly, 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 glvalue that refers to the original object may be used but only in limited ways. For an object under construction or destruction, see 12.7. Otherwise, such a glvalue refers to allocated storage, and using the properties of the glvalue that do not depend on its value is well-defined. The program has undefined behavior if:
— an lvalue-to-rvalue conversion is applied to such a glvalue,
— the glvalue is used to access a non-static data member or call a non-static member function of the object, or
— the glvalue is bound to a reference to a virtual base class, or
— the glvalue is used as the operand of adynamic_cast
or as the operand oftypeid
.
Do not use an object outside of its lifetime, except in the ways described above as being well-defined.
...
Tool | Version | Checker | Description | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Astrée |
| return-reference-local dangling_pointer_use | Partially checked | |||||||||||
Clang |
| -Wdangling-initializer-list | Catches some lifetime issues related to incorrect use of std::initializer_list<> | |||||||||||
CodeSonar |
| IO.UAC | Use after close Use after free | |||||||||||
Helix QAC |
| C++4003, C++4026 DF2812, DF2813, DF2814, DF2930, DF2931, DF2932, DF2933, DF2934, | ||||||||||||
Klocwork |
| CL.FFM.ASSIGN CL.FFM.COPY LOCRET.ARG LOCRET.GLOB LOCRET.RET UFM.DEREF.MIGHT UFM.DEREF.MUST UFM.FFM.MIGHT UFM.FFM.MUST UFM.RETURN.MIGHT UFM.RETURN.MUST UFM.USE.MIGHT UFM.USE.MUST UNINIT.HEAP.MIGHT UNINIT.HEAP.MUST UNINIT.STACK.ARRAY.MIGHT UNINIT.STACK.ARRAY.MUST UNINIT.STACK.ARRAY.PARTIAL.MUST UNINIT.STACK.MIGHT UNINIT.STACK.MUST | ||||||||||||
LDRA tool suite |
| 42 D, 53 D, 77 D, 1 J, 71 S, 565 S | Partially implemented | |||||||||||
Parasoft C/C++test |
| CERT_CPP-EXP54-a | Do not use resources that have been freed | |||||||||||
Parasoft Insure++ | Runtime detection | |||||||||||||
Polyspace Bug Finder |
| CERT C++: EXP54-CPP | Checks for:
Rule partially covered. | |||||||||||
PRQA QA-C++ | ||||||||||||||
Include Page | PRQA QA-C++_V | PRQA QA-C++_V | 2812, 2813, 2814, 2930, 2931, 2932, 2933, 2934, 4003, 4026 | PVS-Studio |
| V758, V1041, V1099 | ||||||||
RuleChecker |
| return-reference-local | Partially checked |
...