In C++, an empty constructor written as `span() = default` differs from one written with an empty body, `span() {}`. When defaulted on its first declaration, the constructor is not user-provided, so `span` remains trivial. With `span s;`, neither form initializes its members. But with `span s{}`, the trivial default constructor allows value-initialization to zero the whole object, including padding. The empty-body constructor is user-provided, so braces call it without zero-initializing the members.
That distinction can affect generated code even when the object’s values are not used. In a loop that builds a span and passes it to `consume`, the exit path creates a value-initialized `box` that is never passed to the function. GCC 15 and 16 nevertheless generate less efficient code for the defaulted constructor: they create a temporary and copy part of it, while the empty-body version writes fields directly where needed. On an Intel Xeon, the benchmark reports about 7.75-8.04 nanoseconds per span for `= default` with those GCC versions, versus roughly 1.73 nanoseconds for `{}`. GCC 14 and Clang 21 show no comparable slowdown, so the performance impact depends on compiler and version.
Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.