No language scares me like C++ does. Look at this page: https://www.learncpp.com/cpp-tutorial/variable-assignment-an...
This is just a single section of the first chapter of a beginner tutorial. And it's already more things to remember than, say, the whole Lua.
The example is pretty contrived because in practice you'd want to zero-initialize the members in the default constructor anyway.
struct span {
const char *p = nullptr;
size_t len = 0;
span() = default; // or span() {}
span(const char *s, size_t n) : p(s), len(n) {}
};
In that case, there is no difference between span s;
and span s{};
There are only few use cases where you want a default constructor that does not initialize its members. One example are wrappers around primitive types where you want to closely preserve the original semantics. Whether that's a good idea in the first place really depends on the use case.For example, std::atomic used to default-initialize the underlying value, which led to many bugs in user code. Since C++20 std::atomic uses value-initialization. See https://cplusplus.github.io/LWG/issue2334. On the one hand, std::atomic is now safer to use, on the other hand, it is not an implicit-lifetime-type anymore, which means you can't put it in shared memory without UB...
Another example is glm::vec, which has actually hit me a few times in my own code. At least they recognized the issue and allowed to override the default behavior with the GLM_FORCE_CTOR_INIT define.
GCC going from effectively the same performance in 14.x to 4x slower in 15.x AND 16.x sounds like a real regression that should be fixed.
For people who don't know, the number in C++14, C++26, ... is how many ways there are to initialize a variable.
obligatory meme
The only sane usage of C++ is to only use a very small subset of its features.
Which is of no consequence to LLVM
Constructors are such an odd duck to me. On the one hand, you have languages like C++ and Swift which have construction as a first-class concept, with tons of rules you need to memorize (Swift's "convenience" vs "designated" initializers are a real treat to unpack).
Then you have languages like Rust, Go, Zig, etc which don't have them at all, constructors are just static functions in the namespace of the type, which return an instance of that type.
For the life of me I've never understood why you'd want the former. I'm sure there's a reason, but I never miss it when using languages in the latter category.
The explanation you typically hear is about OO and inheritance, but I don't buy it: If Animal had a ::new() that initialized private state, Cow could have a ::new() too that could call Animal::new() if it wanted, then do further initialization, etc... I don't think there's anything about inheritance that says constructors are a must. (Edit: In fact, ObjC does exactly this. I should have remembered that given that I did ObjC for a living for a while.)