You can call it a pseudo-constructor if you want, mirroring the terminology for destructor (pseudo-destructor calls are discussed in C++11 §5.2.4). Anyway, int()
is the default value of type int
, i.e. 0.
Re the assertion that "primitive types don't have constructors", that's a rather silly and impractical view. From a formal point of view primitive types don't have constructors, but those who cling to that assertion aren't that much into the formal, at all. Also, from a machine code point of view they don't, but again, to those who think that assertion is important, machine code is like magic. There is a difference, though, namely that from a machine code point of view also common non-primitive POD types can lack constructors (they do have constructors formally), and again I doubt that those who put that assertion forward are even aware of the issues, i.e. I don't think they're qualified to have an opinion. About the same kind of considerations go for any absolute terminological claim: you can be almost sure, when you hear such a claim, that those who make it have almost no idea about what's involved, and that the claim is just impractical & silly.
Instead, when you hear e.g. "constructed" or "constructor call" in the context of primitive types, think about what it meaningfully can mean. The formal is just a matter of definition. The important, except for language lawyer discussions where it anyway is a given, is to have a conceptual model that works.
All the above said, the expression T()
is not a "constructor" formally, it's not a constructor at the machine code level, and it's not a constructor conceptually, in any meaningful conceptual model.
It can be a constructor call (indeed the definition of a default constructor is that it can be called, at the source code level, with no arguments), but note that there's no grammar category for constructor calls.
With all of the above in mind I would just call it a constructor call, and when there is a need to be more precise, for primitive type T
I would call it a pseudo-constructor call.
And if anyone criticized me for that, I'd just challenge them to a duel.
Do note, regarding your statement that
” it's been rehashed over and over that primitive types don't have constructors. For example this bar is not initialized to 0 when I call Foo()
the expression Foo()
performs value initialization, so that the instance (in this case) is zeroed.
Regarding the general lack of initialization of local automatic variables of primitive types without initializers, you have the same situation with any type without a user defined constructor, and even when there is a used defined constructor if that constructor doesn't initialize things.
This sometimes comes as a shock to C++ beginners.
int()
andFoo()
grammatically are "explicit type conversions" in the "functional notation", just likeint(5)
, but with different rules. But I'd guess that only few people use that name to identify that feature. – FrankiefrankincenseT()
creates a value-initialized prvalue – ShelleyFoo
is zero-initialized, and that in turn means that_bar
needs to get the value 0 inFoo()
– ShelleyT()
means value-initialization, rather than understanding what value-initialization means (which is the point of this other question: #1613841 ) – Shelley