Warning C26495

Variable 'variable' is uninitialized. Always initialize a member variable (type.6).


A member variable isn't initialized by a constructor or by an initializer. Make sure all variables are initialized by the end of construction. For more information, see C++ Core Guidelines Type.6 and C.48.

This check is intra-procedural. Whenever there's a function call to a nonconst member function, the check assumes that this member function initializes all of the members. This heuristic can result in missed errors and is in place to avoid false positive results. Moreover, when a member is passed by nonconst reference to a function, the check assumes that the function initializes the member.

Code analysis name: MEMBER_UNINIT


The following sample generates warning C26495 because the member variable value isn't initialized when a MyStruct object is created.

struct MyStruct
    int value;
    MyStruct() {} // C26495, MyStruct::value is uninitialized

To resolve the issue, you can add in-class initialization to all of the member variables.

struct MyStruct
    int value{};  // empty brace initializer sets value to 0
    MyStruct() {} // no warning, MyStruct::value is set via default member initialization

See also