https://github.com/AaronBallman created https://github.com/llvm/llvm-project/pull/147284
cl.exe has /stdc:latest, analogous to /stdc++:latest, which sets the language mode to the latest standard. For C, that's C23. This adds support for the option. Fixes #147233 >From 926fd7ce1264bd263a9fd46409ec7cc8e2d2db27 Mon Sep 17 00:00:00 2001 From: Aaron Ballman <aa...@aaronballman.com> Date: Mon, 7 Jul 2025 07:47:54 -0400 Subject: [PATCH] [clang-cl] Support /stdc:latest cl.exe has /stdc:latest, analogous to /stdc++:latest, which sets the language mode to the latest standard. For C, that's C23. This adds support for the option. Fixes #147233 --- clang/docs/ReleaseNotes.rst | 4 +++- clang/lib/Driver/ToolChains/Clang.cpp | 2 ++ clang/test/Driver/cl-options.c | 6 ++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 3d893e0aa8e2c..2052b43f48070 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -248,7 +248,9 @@ C Language Changes not valid in C++. - The ``[[clang::assume()]]`` attribute is now correctly recognized in C. The ``__attribute__((assume()))`` form has always been supported, so the fix is - specific to the attribute syntax used. + specific to the attribute syntax used.' +- The ``clang-cl`` driver now recognizes ``/stdc:latest`` and sets the language + mode to C23. #GH147233 C2y Feature Support ^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index fea4ee909ff46..8a30b7ea8144a 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -7201,6 +7201,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, LanguageStandard = llvm::StringSwitch<StringRef>(StdArg->getValue()) .Case("c11", "-std=c11") .Case("c17", "-std=c17") + // TODO: add c23 when MSVC supports it. + .Case("clatest", "-std=c23") .Default(""); if (LanguageStandard.empty()) D.Diag(clang::diag::warn_drv_unused_argument) diff --git a/clang/test/Driver/cl-options.c b/clang/test/Driver/cl-options.c index eb079895a0a88..57e16e8795a28 100644 --- a/clang/test/Driver/cl-options.c +++ b/clang/test/Driver/cl-options.c @@ -362,6 +362,12 @@ // RUN: %clang_cl -c -### /std:c11 -- %s 2>&1 | FileCheck -check-prefix CHECK-C11 %s // CHECK-C11: -std=c11 +// RUN: %clang_cl -c -### /std:c17 -- %s 2>&1 | FileCheck -check-prefix CHECK-C17 %s +// CHECK-C17: -std=c17 + +// RUN: %clang_cl -c -### /std:clatest -- %s 2>&1 | FileCheck -check-prefix CHECK-CLATEST %s +// CHECK-CLATEST: -std=c23 + // For some warning ids, we can map from MSVC warning to Clang warning. // RUN: %clang_cl -wd4005 -wd4100 -wd4910 -wd4996 -wd12345678 -### -- %s 2>&1 | FileCheck -check-prefix=Wno %s // Wno: "-cc1" _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits