# GCC 15 and 16 make \`= default\` constructors four times slower than \`{}\`

Original title: In C++, = default and {} are not the same constructor

> Hacker News story 50643199 · language: en · submitted 2026-11-25
> Web version: https://zeli.app/story/50643199
> About this feed: https://zeli.app/llms.txt · Agent guide: https://zeli.app/skill.md

▲ 92 · by [surprisetalk](<https://news.ycombinator.com/user?id=surprisetalk>) · 💬 153
[original](<https://lemire.me/blog/2026/11/02/default-and-braces-are-not-the-same-constructor/>) · [HN discussion](<https://news.ycombinator.com/item?id=50643199>)

## Summary

Writing an empty default constructor as `span() = default` versus `span() {}` looks cosmetic but changes whether the type is trivial. Daniel Lemire benchmarks 100 million spans and finds GCC 15 and 16 take about 8 ns per span with `= default`, versus roughly 1.7 ns with the braces version, because the trivial path forces extra temporary copies. GCC 14 and clang 21 show no gap.

## Key quote

> With GCC 15 and GCC 16, the `= default` version is over four times slower.

## HN discussion (153 comments)

### [ninkendo](<https://news.ycombinator.com/item?id=50643643>)

> 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.)

### [morning-coffee](<https://news.ycombinator.com/item?id=50647562>)

> This is one of the many reasons I left C++ (after investing over 20 years professionally in it) for Rust. Sometimes it is just better to get on with life than deal with pedantic minutiae all the time.

### [raincole](<https://news.ycombinator.com/item?id=50643425>)

> 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.

### [spacechild1](<https://news.ycombinator.com/item?id=50644396>)

> 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.

### [rcleveng](<https://news.ycombinator.com/item?id=50646272>)

> 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.

### [dist-epoch](<https://news.ycombinator.com/item?id=50646415>)

> For people who don't know, the number in C++14, C++26, ... is how many ways there are to initialize a variable.

### [BiraIgnacio](<https://news.ycombinator.com/item?id=50645951>)

> obligatory meme
>
> https://imgur.com/forest-gump-c-3wlxtI0

### [vinyl7](<https://news.ycombinator.com/item?id=50643510>)

> The only sane usage of C++ is to only use a very small subset of its features.

---

## Cite

- Page: https://zeli.app/story/50643199
- Date: 2026-11-25
- Source: lemire.me (https://lemire.me/blog/2026/11/02/default-and-braces-are-not-the-same-constructor/)
- Hacker News: https://news.ycombinator.com/item?id=50643199

## Other languages

- zh: https://zeli.app/zh/story/50643199 · markdown: https://zeli.app/zh/story/50643199.md
- ja: https://zeli.app/ja/story/50643199 · markdown: https://zeli.app/ja/story/50643199.md
- ko: https://zeli.app/ko/story/50643199 · markdown: https://zeli.app/ko/story/50643199.md
- de: https://zeli.app/de/story/50643199 · markdown: https://zeli.app/de/story/50643199.md
- es: https://zeli.app/es/story/50643199 · markdown: https://zeli.app/es/story/50643199.md
- ru: https://zeli.app/ru/story/50643199 · markdown: https://zeli.app/ru/story/50643199.md
