JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.
If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.
If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.
| CodeSonar® 9.0p0 Hot Tips | CONFIDENTIAL | CodeSecure Inc |
The ordering in the member initializer list for a class constructor does not match the order in which the initializers will be invoked.
The order of invocation for member initializers is specified in the C++ standard and is independent of their order in the initializer list. A warning of this class is issued if a constructor for class C is invoked at least once in the analyzed code but the member initializer list for the constructor does not meet all of the following requirements.
A member initializer list that does not reflect this ordering may cause confusion for human readers.
| Class Name | Out of Order Member Initializers | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Significance | style | |||||||||||||||
| Mnemonic | LANG.STRUCT.INIT.OOMI | |||||||||||||||
| Categories |
|
|||||||||||||||
| Availability | Available for C++ only (not C). |
|||||||||||||||
| Enabling | Checks for this warning class are disabled by default,
and require the unnormalized
C ASTs for the project. To enable them, add the following
WARNING_FILTER rule and RETAIN_UNNORMALIZED_C_AST specification to the project configuration file.
RETAIN_UNNORMALIZED_C_AST = Yes WARNING_FILTER += allow class="Out of Order Member Initializers" |
namespace lang_struct_init_oomi{
class VirtualBase {
public:
VirtualBase(void): second_int(1), // 'Out of Order Member Initializers' warning issued here
first_int(2) {};
VirtualBase(int i){}
private:
int first_int;
int second_int;
};
class FirstClass {
public:
FirstClass(void){}
FirstClass(int i){}
};
class SecondClass {
public:
SecondClass(void){}
SecondClass(int i){}
};
class Derived: virtual VirtualBase, FirstClass, SecondClass {
public:
Derived(void) : mychar('x'), // 'Out of Order Member Initializers' warning issued here
FirstClass(1), // 'Out of Order Member Initializers' warning issued here
VirtualBase(2) {}
Derived(int i) : SecondClass(i), // 'Out of Order Member Initializers' warning issued here
FirstClass(i) {}
Derived(char c) : VirtualBase(1), // ok:
FirstClass(1), // all initializer list ordering requirements
SecondClass(1), // met for this constructor
mychar(c) {}
private:
char mychar;
};
Derived d1; // invokes Derived::Derived(void)
Derived d2(2); // invokes Derived::Derived(int i), which in turn invokes VirtualBase::VirtualBase(void)
Derived d3('c'); // invokes Derived::Derived(char c)
}
The following configuration file parameters affect checks for this warning class.