I have the following class definition:
class T
{
string text;
public:
T() : text{}
{
// ...
}
T(T &other)
{
// ...
}
};
And the following initialization:
T cp_f = T();
From what I can understand about object initialization this is a value (default)
initialization (T()
) followed by a copy
initialization (T cp_f = ...
). But when I execute this code the copy constructor is never called. At first I assumed that the compiler is optimizing the redundant temporary but even with optimization turned off the behavior persists.
Why this expression does not result in a copy initialization?
PS: I'm using the VC++ compiler version 19.10.25017 for x86/