From 69c24d6368066320956d8a0d062de7f823d41b05 Mon Sep 17 00:00:00 2001 From: chn Date: Wed, 11 Dec 2024 22:33:40 +0800 Subject: [PATCH] add C++23 support --- lib/Interpreter/CIFactory.cpp | 15 +++++++++++---- lib/Interpreter/IncrementalCUDADeviceCompiler.cpp | 2 ++ tools/Jupyter/kernel/clingkernel.py | 4 ++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/Interpreter/CIFactory.cpp b/lib/Interpreter/CIFactory.cpp index 385c036825..d33ce3a003 100644 --- a/lib/Interpreter/CIFactory.cpp +++ b/lib/Interpreter/CIFactory.cpp @@ -61,14 +61,18 @@ using namespace cling; namespace { static constexpr unsigned CxxStdCompiledWith() { + // The value of __cplusplus in GCC < 14 is 202100L when -std=c++2b or + // -std=c++23 is specified, thus we relax the check to 202100L. +#if __cplusplus >= 202100L + return 23; +#elif __cplusplus > 201703L + return 20; +#elif __cplusplus > 201402L + return 17; // The value of __cplusplus in GCC < 5.0 (e.g. 4.9.3) when // either -std=c++1y or -std=c++14 is specified is 201300L, which fails // the test for C++14 or more (201402L) as previously specified. // I would claim that the check should be relaxed to: -#if __cplusplus > 201703L - return 20; -#elif __cplusplus > 201402L - return 17; #elif __cplusplus > 201103L || (defined(_WIN32) && _MSC_VER >= 1900) return 14; #elif __cplusplus >= 201103L @@ -941,6 +945,8 @@ namespace { // Sanity check that clang delivered the language standard requested if (CompilerOpts.DefaultLanguage(&LangOpts)) { switch (CxxStdCompiledWith()) { + case 23: assert(LangOpts.CPlusPlus23 && "Language version mismatch"); + LLVM_FALLTHROUGH; case 20: assert(LangOpts.CPlusPlus20 && "Language version mismatch"); LLVM_FALLTHROUGH; case 17: assert(LangOpts.CPlusPlus17 && "Language version mismatch"); @@ -1343,6 +1349,7 @@ namespace { // and by enforcing the std version now cling is telling clang what to // do, rather than after clang has dedcuded a default. switch (CxxStdCompiledWith()) { + case 23: argvCompile.emplace_back("-std=c++23"); break; case 20: argvCompile.emplace_back("-std=c++20"); break; case 17: argvCompile.emplace_back("-std=c++17"); break; case 14: argvCompile.emplace_back("-std=c++14"); break; diff --git a/lib/Interpreter/IncrementalCUDADeviceCompiler.cpp b/lib/Interpreter/IncrementalCUDADeviceCompiler.cpp index ac6bd0e894..a492add8a0 100644 --- a/lib/Interpreter/IncrementalCUDADeviceCompiler.cpp +++ b/lib/Interpreter/IncrementalCUDADeviceCompiler.cpp @@ -117,6 +117,8 @@ namespace cling { cppStdVersion = "-std=c++1z"; if (langOpts.CPlusPlus20) cppStdVersion = "-std=c++20"; + if (langOpts.CPlusPlus23) + cppStdVersion = "-std=c++23"; if (cppStdVersion.empty()) llvm::errs() diff --git a/tools/Jupyter/kernel/clingkernel.py b/tools/Jupyter/kernel/clingkernel.py index 17fcbd116e..17b4d24f23 100644 --- a/tools/Jupyter/kernel/clingkernel.py +++ b/tools/Jupyter/kernel/clingkernel.py @@ -90,8 +90,8 @@ def _banner_default(self): flush_interval = Float(0.25, config=True) std = CaselessStrEnum(default_value='c++11', - values = ['c++11', 'c++14', 'c++1z', 'c++17', 'c++20', 'c++2b'], - help="C++ standard to use, either c++2b, c++20, c++17, c++1z, c++14 or c++11").tag(config=True); + values = ['c++11', 'c++14', 'c++1z', 'c++17', 'c++20', 'c++2b', 'c++23' ], + help="C++ standard to use, either c++23, c++2b, c++20, c++17, c++1z, c++14 or c++11").tag(config=True); def __init__(self, **kwargs): super(ClingKernel, self).__init__(**kwargs)