Update by new experiences and observations:
- The contents of the disassembly window showed, that the result of the const-call
to std::wstring::capacity
is 8!
- But the watch window and the tooltip of the variable show 7.
The hypothesis of a colleague is, that the debugger calls the constexpr method capacity non-const, gets the differing result of 7 and visualizes it.
A reason to look into the disassembly window was the unexpected behavior in the following code:
const auto nInitCap = std::wstring().capacity();
const auto nCap = str.capacity();
if (nCap != nInitCap)
std::wcout << "capacity " << nCap << "is not equal to the initial capacity " << nInitCap << std::endl;
if (nCap > nInitCap)
std::wcout << "capacity " << nCap << "is greater than the initial capacity " << nInitCap << std::endl;
The debugger showed for the variables:
nInitCap: 7
nCap: 7
But the code printed out:
capacity 7 is not equal to the initial capacity 7
The capacity call to the const-constructed temporary object returns 8, as to be seen in the disassembly, so the behavior is explainable, even if the debugger of VS2022 17.0.5 shows 7