Skip to content

Commit

Permalink
add C++23 support
Browse files Browse the repository at this point in the history
  • Loading branch information
CHN-beta authored and jenkins committed Dec 14, 2024
1 parent 5ea7949 commit 69c24d6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
15 changes: 11 additions & 4 deletions lib/Interpreter/CIFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions lib/Interpreter/IncrementalCUDADeviceCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions tools/Jupyter/kernel/clingkernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 69c24d6

Please sign in to comment.