cpp_weekly
cpp_weekly copied to clipboard
C is getting auto!
and it's weird
auto auto i = 5;
auto int j = 6;
A related feature that C is getting is storage-class specifiers for compound literals. As you might remember, one of the big things keeping C++ from adopting compound literals is that they were always block scoped. C++ couldn't change that itself, because that would ruin C compatibility which was the biggest selling point of the feature.
// Since compound literals are block scope, this was technically illegal according to the standard,
// but Clang and GCC allow it as an extension.
static struct foo x = (struct foo){1, 'a', 'b'};
But this new feature allows you to set the storage class specifier like so:
// This is legal now! But not implemented yet. :(
static struct foo x = (constexpr struct foo){1, 'a', 'b'};
// And obviously works much better with auto.
static auto x = (constexpr struct foo){1, 'a', 'b'};
So, I'd expect to see some movement on adding this for C++26 (if it can get through the backlog).