C23 constexpr + auto + type shouldn't be a valid combination (original) (raw)

The following program demonstrates this issue:

int main(){ constexpr auto int x={}; }

This program is invalid because:

thread_local shall not appear in the declaration specifiers of a function declaration. auto shall only
appear in the declaration specifiers of an identifier with file scope or along with other storage-class
specifiers if the type is to be inferred from an initializer.

...

If auto appears with another storage-class specifier, or if it appears in a declaration at file scope, it is
ignored for the purposes of determining a storage duration or linkage. In this case, it indicates only
that the declared type may be inferred.

Section 6.7.2 "Storage-class specifiers" Paragraphs 4 and 15 ISO/IEC 9899:2024

constexpr is a storage-class specifier, so here auto is specifying type inference (and if it wasn't, it would violate the constraint in paragraph 4). I can't find any wording to say that using a type specifier with auto for type inference is invalid, but {} surely isn't valid with type inference. Note that Clang doesn't accept the following:

auto int x={}; int main(){}

GCC also doesn't accept either program.