Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ Non-comprehensive list of changes in this release
allocation functions with a token ID can be enabled via the
``-fsanitize=alloc-token`` flag.

- Clang now rejects the invalid use of ``constexpr`` with ``auto`` and an explicit type in C. (#GH163090)

New Compiler Flags
------------------
- New option ``-fno-sanitize-debug-trap-reasons`` added to disable emitting trap reasons into the debug info when compiling with trapping UBSan (e.g. ``-fsanitize-trap=undefined``).
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/Sema/DeclSpec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1369,7 +1369,8 @@ void DeclSpec::Finish(Sema &S, const PrintingPolicy &Policy) {

if (S.getLangOpts().C23 &&
getConstexprSpecifier() == ConstexprSpecKind::Constexpr &&
StorageClassSpec == SCS_extern) {
getTypeSpecType() != TST_unspecified &&
(StorageClassSpec == SCS_extern || StorageClassSpec == SCS_auto)) {
S.Diag(ConstexprLoc, diag::err_invalid_decl_spec_combination)
<< DeclSpec::getSpecifierName(getStorageClassSpec())
<< SourceRange(getStorageClassSpecLoc());
Expand Down
27 changes: 27 additions & 0 deletions clang/test/Parser/c2x-auto.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,30 @@ void atomic(void) {
void attributes(void) {
auto ident [[clang::annotate("this works")]] = 12; // c17-error {{type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int}}
}

/** GH163090 */
constexpr auto int a1 = 0; // c23-error {{illegal storage class on file-scoped variable}} \
c23-error {{cannot combine with previous 'auto' declaration specifier}} \
c17-error {{illegal storage class on file-scoped variable}} \
c17-error {{unknown type name 'constexpr'}}

constexpr int auto a2 = 0; // c23-error {{cannot combine with previous 'int' declaration specifier}} \
c17-error {{illegal storage class on file-scoped variable}} \
c17-error {{unknown type name 'constexpr'}}

auto int b1 = 0; // c23-error {{illegal storage class on file-scoped variable}} \
c17-error {{illegal storage class on file-scoped variable}}

int auto b2 = 0; // c23-error {{cannot combine with previous 'int' declaration specifier}} \
c17-error {{illegal storage class on file-scoped variable}}

void f() {
constexpr auto int c1 = 0; // c23-error {{cannot combine with previous 'auto' declaration specifier}} \
c17-error {{use of undeclared identifier 'constexpr'}}

constexpr int auto c2 = 0; // c23-error {{cannot combine with previous 'int' declaration specifier}} \
c17-error {{use of undeclared identifier 'constexpr'}}

auto int d1 = 0;
int auto d2 = 0; // c23-error {{cannot combine with previous 'int' declaration specifier}}
Comment on lines +157 to +158

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the order of keywords here significant?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made a separate issue for this: #164121

}