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.2p0 CONFIDENTIAL CodeSecure Inc
C and C++


LANG.STRUCT.INIT.OOMI : Out of Order Member Initializers

要旨

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.

プロパティ

クラス名 Out of Order Member Initializers
日本語クラス名 Out of Order Member Initializers
クラス分類 スタイル (style)
ニーモニック LANG.STRUCT.INIT.OOMI
カテゴリー
AUTOSARC++14 AUTOSARC++14:A8-5-1 In an initialization list, the order of initialization shall be following: (1) virtual base classes in depth and left to right order of the inheritance graph, (2) direct base classes in left to right order of inheritance list, (3) non-static data members in the order they were declared in the class definition.
CERT-CPP CERT-CPP:OOP53-CPP Write constructor member initializers in the canonical order
JSF++ JSF++:75 Members of the initialization list shall be listed in the order in which they are declared in the class.
  JSF++:210 Algorithms shall not make assumptions concerning how data is represented in memory (e.g. big endian vs. little endian, base class subobject ordering in derived classes, nonstatic data member ordering across access specifiers, etc.)
  JSF++:210.1 Algorithms shall not make assumptions concerning the order of allocation of nonstatic data members separated by an access specifier.
対応言語 C++ のみ利用可能です。 C は利用できません。
有効/無効設定 Checks for this warning class are enabled by default. However, warning instances of this class that are issued as parser errors (rather than parser warnings) will be discarded when using factory configuration settings. To prevent these instances from being discarded, add the following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += allow class="Out of Order Member Initializers"
To disable checks for this warning class, add the following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += discard class="Out of Order Member Initializers"

namespace lang_struct_init_oomi{

  class VirtualBase {
  public:
    VirtualBase(void): second_int(1),
                       first_int(2) {}; // 'Out of Order Member Initializers' warning issued here
    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'),
                    FirstClass(1),    // 'Out of Order Member Initializers' warning issued here
                    VirtualBase(2) {}

    Derived(int i) : SecondClass(i),
                     FirstClass(i) {}  // 'Out of Order Member Initializers' warning issued here

    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) 
}

関連のある設定ファイルパラメータ

設定ファイルの以下のパラメータがこのワーニングクラスのチェックに影響します。

 

To report problems with this documentation, please visit https://support.codesecure.com/.