...
To default-initialize an object of type
Tmeans:
— ifTis a (possibly cv-qualified) class type, the default constructor forTis called (and the initialization is ill-formed ifThas no default constructor or overload resolution results in an ambiguity or in a function that is deleted or inaccessible from the context of the initialization);
— ifTis an array type, each element is default-initialized;
— otherwise, no initialization is performed.
If a program calls for the default initialization of an object of a const-qualified typeT,Tshall be a class type with a user-provided default constructor.
As a result, objects of type T with automatic or dynamic storage duration must be explicitly initialized before having their value read as part of an expression unless T is a class type or an array thereof or is an unsigned narrow character type. If T is an unsigned narrow character type, it may be used to initialize an object of unsigned narrow character type, which results in both objects having an indeterminate value. This technique can be used to implement copy operations such as std::memcpy() without triggering undefined behavior.
...
Tool | Version | Checker | Description | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Astrée |
| uninitialized-read | Partially checked | |||||||||||
| Clang |
| -Wuninitialized clang-analyzer-core.UndefinedBinaryOperatorResult | Does not catch all instances of this rule, such as uninitialized values read from heap-allocated memory. | |||||||||||
| CodeSonar |
| LANG.STRUCT.RPL | Return pointer to local Uninitialized variable | |||||||||||
| Helix QAC |
| DF726, DF2727, DF2728, DF2961, DF2962, DF2963, DF2966, DF2967, DF2968, DF2971, DF2972, DF2973, DF2976, DF2977, DF978 | ||||||||||||
| Klocwork |
| UNINIT.CTOR.MIGHT UNINIT.CTOR.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 |
| 53 D, 69 D, 631 S, 652 S | Partially implemented | |||||||||||
| Parasoft C/C++test |
| CERT_CPP-EXP53-a | Avoid use before initialization | |||||||||||
| Parasoft Insure++ | Runtime detection | |||||||||||||
| Polyspace Bug Finder |
| CERT C++: EXP53-CPP | Checks for:
Rule partially covered. | |||||||||||
| PRQA QA-C++ | ||||||||||||||
| Include Page | PRQA QA-C++_V | PRQA QA-C++_V | 2726, 2727, 2728, 2961, 2962, 2963, 2966, 2967, 2968, 2971, 2972, 2973, 2976, 2977, 2978 | PVS-Studio |
| V546, V573, V614, V670, V679, V730, V788, V1007, V1050 | ||||||||
| RuleChecker |
| uninitialized-read | Partially checked |
...