Skip to content

Commit 3856379

Browse files
committed
[Clang] disallow constexpr with auto and explicit type in C23
1 parent bed17c0 commit 3856379

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

clang/docs/ReleaseNotes.rst

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

272+
- Clang now rejects the invalid use of ``constexpr`` with ``auto`` and an explicit type. (#GH163090)
273+
272274
New Compiler Flags
273275
------------------
274276
- 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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1369,7 +1369,7 @@ void DeclSpec::Finish(Sema &S, const PrintingPolicy &Policy) {
13691369

13701370
if (S.getLangOpts().C23 &&
13711371
getConstexprSpecifier() == ConstexprSpecKind::Constexpr &&
1372-
StorageClassSpec == SCS_extern) {
1372+
(StorageClassSpec == SCS_extern || StorageClassSpec == SCS_auto)) {
13731373
S.Diag(ConstexprLoc, diag::err_invalid_decl_spec_combination)
13741374
<< DeclSpec::getSpecifierName(getStorageClassSpec())
13751375
<< SourceRange(getStorageClassSpecLoc());

clang/test/Parser/c2x-auto.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ auto basic_usage(auto auto) { // c23-error {{'auto' not allowed in function pr
6262

6363
int auto_cxx_decl = auto(0); // expected-error {{expected expression}}
6464

65+
constexpr auto int x = 0; // c23-error {{cannot combine with previous 'auto' declaration specifier}} \
66+
c17-error {{use of undeclared identifier 'constexpr'}}
6567
return c;
6668
}
6769

0 commit comments

Comments
 (0)