Usage of non-initialized class field 'myMap' when called from function 'main'

17 hours ago 3
ARTICLE AD BOX

MRE:

#include <unordered_map> #include <string> class MyClass { private: std::unordered_map<std::string, int> myMap; public: MyClass() : myMap() {} }; int main() { // Create a MyClass object on the heap const auto* my_class = new MyClass(); delete my_class; }

I'm struggling to understand why I have the warning (in CLion)

Usage of non-initialized class field 'myMap' when called from function 'main'

I even added myMap to the initializer list in case that'd help, but it doesn't. Weirdly enough, if I set a capacity, the warning disappears.

Proof

Without capacity: enter image description here With capacity: enter image description here

I have

set(CMAKE_CXX_STANDARD 23)

in my CMakeLists.txt

And

cmake_minimum_required(VERSION 3.30)

Creating the object on the stack also results in the same warning in CLion:

#include <unordered_map> #include <string> class MyClass { private: std::unordered_map<std::string, int> myMap; public: MyClass() : myMap() {} }; int main() { const MyClass my_class{}; }
Read Entire Article