Skip to content

Commit 1f2d51d

Browse files
author
git apple-llvm automerger
committed
Merge commit 'dc27696e9e25' from llvm.org/main into next
2 parents a4dc257 + dc27696 commit 1f2d51d

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,8 @@ Non-comprehensive list of changes in this release
271271
allocation functions with a token ID can be enabled via the
272272
``-fsanitize=alloc-token`` flag.
273273

274+
- Clang now rejects the invalid use of ``constexpr`` with ``auto`` and an explicit type in C. (#GH163090)
275+
274276
New Compiler Flags
275277
------------------
276278
- 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``).

clang/lib/Sema/DeclSpec.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1369,7 +1369,8 @@ void DeclSpec::Finish(Sema &S, const PrintingPolicy &Policy) {
13691369

13701370
if (S.getLangOpts().C23 &&
13711371
getConstexprSpecifier() == ConstexprSpecKind::Constexpr &&
1372-
StorageClassSpec == SCS_extern) {
1372+
getTypeSpecType() != TST_unspecified &&
1373+
(StorageClassSpec == SCS_extern || StorageClassSpec == SCS_auto)) {
13731374
S.Diag(ConstexprLoc, diag::err_invalid_decl_spec_combination)
13741375
<< DeclSpec::getSpecifierName(getStorageClassSpec())
13751376
<< SourceRange(getStorageClassSpecLoc());

clang/test/Parser/c2x-auto.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,30 @@ void atomic(void) {
130130
void attributes(void) {
131131
auto ident [[clang::annotate("this works")]] = 12; // c17-error {{type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int}}
132132
}
133+
134+
/** GH163090 */
135+
constexpr auto int a1 = 0; // c23-error {{illegal storage class on file-scoped variable}} \
136+
c23-error {{cannot combine with previous 'auto' declaration specifier}} \
137+
c17-error {{illegal storage class on file-scoped variable}} \
138+
c17-error {{unknown type name 'constexpr'}}
139+
140+
constexpr int auto a2 = 0; // c23-error {{cannot combine with previous 'int' declaration specifier}} \
141+
c17-error {{illegal storage class on file-scoped variable}} \
142+
c17-error {{unknown type name 'constexpr'}}
143+
144+
auto int b1 = 0; // c23-error {{illegal storage class on file-scoped variable}} \
145+
c17-error {{illegal storage class on file-scoped variable}}
146+
147+
int auto b2 = 0; // c23-error {{cannot combine with previous 'int' declaration specifier}} \
148+
c17-error {{illegal storage class on file-scoped variable}}
149+
150+
void f() {
151+
constexpr auto int c1 = 0; // c23-error {{cannot combine with previous 'auto' declaration specifier}} \
152+
c17-error {{use of undeclared identifier 'constexpr'}}
153+
154+
constexpr int auto c2 = 0; // c23-error {{cannot combine with previous 'int' declaration specifier}} \
155+
c17-error {{use of undeclared identifier 'constexpr'}}
156+
157+
auto int d1 = 0;
158+
int auto d2 = 0; // c23-error {{cannot combine with previous 'int' declaration specifier}}
159+
}

0 commit comments

Comments
 (0)