April 25th, 2025

New C++ features in GCC 15

GCC 15.1, releasing in April or May 2025, will enhance C++ with features like pack indexing, structured binding attributes, and experimental support for C++20, C++23, and C++26, while deprecating some features.

Read original articleLink Icon
New C++ features in GCC 15

The upcoming release of GCC 15.1, expected in April or May 2025, will introduce several new features and improvements for C++ developers. This version will be the default compiler in Fedora 42 and will be available to Red Hat Enterprise Linux users through the Red Hat GCC Toolset. Notably, GCC 15 will support experimental features from C++20, C++23, and C++26, with the default dialect remaining at -std=gnu++17. Key features include pack indexing, which allows indexing of template argument packs, and the ability to add attributes to structured bindings. Additionally, C++26 will introduce the option to provide a reason for deleted functions, variadic friends, and constexpr placement new. Other enhancements include structured binding declarations in condition statements, improved diagnostics for qualified lookup failures, and fixes for range-based for loops. GCC 15 will also deprecate certain features, such as the use of variadic ellipses without preceding commas and array comparisons. Overall, these updates aim to enhance the usability and functionality of C++ in GCC, making it easier for developers to write and maintain code.

- GCC 15.1 is set to release in April or May 2025, featuring numerous enhancements for C++.

- New features include pack indexing, attributes for structured bindings, and improved diagnostics.

- Experimental support for C++20, C++23, and C++26 features will be available.

- Deprecated features include variadic ellipses without commas and array comparisons.

- GCC 15 aims to improve usability and functionality for C++ developers.

Link Icon 5 comments
By @tlb - 1 day
> Fix for range-based for loops

Oh man, having different compilers in c++20 mode handle things differently is going to cause more grief, not less.

Reminder: Prior to c++23 the following is broken:

  vector<int> const &identity(vector<int> const &a) { return a; }

  for (auto a : identity(vector<int>{1,2})) { ... }
That's because the lifetime of the vector isn't extended through the life of the for loop. That is, the vector is destructed right after identity returns, and the for loop ends up trying to iterate through a vector that's been destructed.

But now gcc in c++20 with -frange-for-ext-temps mode will extend the lifetime of the vector and the above code will work, and people will write code like that, and it'll break mysteriously on other c++20 compilers. The usual way it breaks is that the for loop does nothing because in destructing the vector it sets the begin and end pointers to null, so it's a subtle kind of breakage.

BTW clang with -Wall doesn't complain about the above broken code.

By @pjmlp - 1 day
For me one of the big improvements is the modules support, GCC is now joining clang and MSVC, kudos to the team.
By @LorenDB - 1 day
#embed should make it fairly easy to write an installer from scratch. You'll still have to handle things like registry keys on Windows manually, but the barrier to entry for developing installers will be much lower.
By @ashvardanian - 1 day
`#embed`, finally! Fixing UB in range-based `for` loops is also a good one!