Skip to content

Conversation

@AaronBallman
Copy link
Collaborator

@AaronBallman AaronBallman commented Jul 7, 2025

cl.exe has /std:clatest, analogous to /std:c++latest, which sets the language mode to the latest standard. For C, that's C23. This adds support for the option.

Fixes #147233

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 llvm#147233
@AaronBallman AaronBallman added clang Clang issues not falling into any other category c clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang-cl `clang-cl` driver. Don't use for other compiler parts diverges-from:msvc Does the clang frontend diverge from msvc on this issue labels Jul 7, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 7, 2025

@llvm/pr-subscribers-clang-driver

Author: Aaron Ballman (AaronBallman)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/147284.diff

3 Files Affected:

  • (modified) clang/docs/ReleaseNotes.rst (+3-1)
  • (modified) clang/lib/Driver/ToolChains/Clang.cpp (+2)
  • (modified) clang/test/Driver/cl-options.c (+6)
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" 
@llvmbot
Copy link
Member

llvmbot commented Jul 7, 2025

@llvm/pr-subscribers-clang

Author: Aaron Ballman (AaronBallman)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/147284.diff

3 Files Affected:

  • (modified) clang/docs/ReleaseNotes.rst (+3-1)
  • (modified) clang/lib/Driver/ToolChains/Clang.cpp (+2)
  • (modified) clang/test/Driver/cl-options.c (+6)
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" 
@philnik777
Copy link
Contributor

You've got the same typo (?) in a bunch of places. You have /stdc:latest instead of /std:clatest. Same for /std:c++latest.

@AaronBallman
Copy link
Collaborator Author

You've got the same typo (?) in a bunch of places. You have /stdc:latest instead of /std:clatest. Same for /std:c++latest.

Good catch! Sheesh, fingers. Work!

@AaronBallman AaronBallman changed the title [clang-cl] Support /stdc:latest [clang-cl] Support /std:clatest Jul 7, 2025
@AaronBallman
Copy link
Collaborator Author

You've got the same typo (?) in a bunch of places. You have /stdc:latest instead of /std:clatest. Same for /std:c++latest.

Good catch! Sheesh, fingers. Work!

Those are all addressed. This is what I get for typing __STDC_* as often as I do. :-D

Copy link
Collaborator

@zmodem zmodem left a comment

Choose a reason for hiding this comment

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

Thanks!

(For my curiosity: seems the flag was added to the MSVC docs in MicrosoftDocs/cpp-docs@0b7e40a)

@AaronBallman AaronBallman merged commit 6063031 into llvm:main Jul 7, 2025
9 of 10 checks passed
@AaronBallman AaronBallman deleted the aballman-gh147233 branch July 7, 2025 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang Clang issues not falling into any other category clang-cl `clang-cl` driver. Don't use for other compiler parts diverges-from:msvc Does the clang frontend diverge from msvc on this issue

5 participants