This is an automated email from the ASF dual-hosted git repository.
tqchen pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm-ffi.git
The following commit(s) were added to refs/heads/main by this push:
new 7b5532a8 [BUILD] Require C++20 for TVM FFI (#920)
7b5532a8 is described below
commit 7b5532a830d1c69dd789298d4703c3c884b7d66d
Author: Yaxing Cai <[email protected]>
AuthorDate: Thu Nov 5 01:26:10 2026 +0800
[BUILD] Require C++20 for TVM FFI (#920)
Raise TVM FFI's required C++ standard from C++17 to C++20. Core, Cython,
and test builds, exported CMake targets, `tvm-ffi-config --cxxflags`,
and Python C++/CUDA extension builds now use C++20. Update the
documentation, examples, and ORC JIT build settings accordingly.
C++20 changes `u8` literals to `char8_t`, so preserve the JSON tests'
expected UTF-8 bytes with explicit byte literals. Keep constraints and
integer-comparison syntax rewrites optional in clang-tidy, and preserve
the existing function-cell initialization and exact JSON decimal fixture
with targeted suppressions.
The independent Torch C-DLPack addon continues selecting its standard
from the installed Torch version; it does not include TVM FFI's C++
headers.
Validation on macOS arm64, Apple Clang 21, Python 3.13:
- C++ suite: 549 passed; 2 disabled.
- Config, build/load, and generated C++ ABI header tests: 43 passed; 3
GPU-dependent tests skipped.
- All pre-commit hooks passed; clang-tidy 21.1.1 passed on the changed
C++ test.
- Downstream CMake quickstart built as C++20 even when the consumer
requested C++17; the C11 ABI example also built.
Local builds used an identical source snapshot and virtual environment
under a path without spaces because existing libbacktrace and
extension-linker path handling rejects this workspace path. Linux,
Windows, GPU, and ORC JIT runtime coverage was not run locally.
---
.agents/skills/devtools/SKILL.md | 2 +-
.clang-tidy | 3 ++
AGENTS.md | 4 +--
CMakeLists.txt | 8 ++---
addons/tvm_ffi_orcjit/CMakeLists.txt | 2 +-
addons/tvm_ffi_orcjit/README.md | 4 +--
.../examples/quick-start/CMakeLists.txt | 2 +-
addons/tvm_ffi_orcjit/tests/CMakeLists.txt | 2 +-
cmake/tvm_ffi-config.cmake | 4 +--
docs/conf.py | 2 +-
docs/dev/source_build.rst | 4 +--
docs/get_started/quickstart.rst | 2 +-
docs/guides/cubin_launcher.rst | 2 +-
docs/packaging/cpp_tooling.rst | 2 +-
.../embedded_cubin/include_bin2c/CMakeLists.txt | 2 +-
include/tvm/ffi/extra/cuda/cubin_launcher.h | 2 +-
include/tvm/ffi/function.h | 3 +-
python/tvm_ffi/config.py | 2 +-
python/tvm_ffi/cpp/extension.py | 34 +++++++++++-----------
python/tvm_ffi/dataclasses/gen_abi_cpp.py | 2 +-
tests/cpp/CMakeLists.txt | 2 +-
tests/cpp/extra/test_json_parser.cc | 14 ++++-----
tests/python/test_libinfo.py | 2 +-
23 files changed, 55 insertions(+), 51 deletions(-)
diff --git a/.agents/skills/devtools/SKILL.md b/.agents/skills/devtools/SKILL.md
index 5d85232a..62542940 100644
--- a/.agents/skills/devtools/SKILL.md
+++ b/.agents/skills/devtools/SKILL.md
@@ -11,7 +11,7 @@ Condensed reference from `docs/dev/`. Use this when working
on the TVM-FFI codeb
## Prerequisites
- **Python**: 3.9+ (managed via `uv`; default virtualenv at `.venv`)
-- **Compiler**: C++17-capable toolchain (GCC/Clang on Linux, Apple Clang on
macOS, MSVC on Windows)
+- **Compiler**: C++20-capable toolchain (GCC/Clang on Linux, Apple Clang on
macOS, MSVC on Windows)
- **Build tools**: CMake 3.26+, Ninja
- **Source**: Always clone with `--recursive`, or run `git submodule update
--init --recursive`
diff --git a/.clang-tidy b/.clang-tidy
index 3842dc7a..bebf3af0 100644
--- a/.clang-tidy
+++ b/.clang-tidy
@@ -1,4 +1,5 @@
# -clang-analyzer-unix.Malloc is disabled due to false positives
+# C++20 constraints and integer comparison rewrites remain optional.
Checks: >
clang-diagnostic-*,
clang-analyzer-*,
@@ -11,6 +12,8 @@ Checks: >
-modernize-concat-nested-namespaces,
-modernize-use-auto,
-modernize-use-nodiscard,
+ -modernize-use-constraints,
+ -modernize-use-integer-sign-comparison,
-modernize-return-braced-init-list,
-modernize-avoid-c-arrays,
-bugprone-easily-swappable-parameters,
diff --git a/AGENTS.md b/AGENTS.md
index 5b2e143f..354f33c2 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -20,7 +20,7 @@
## What is this project?
TVM FFI is an open ABI and FFI (Foreign Function Interface) for machine
learning
-systems. It provides a stable C ABI, C++17 API, Python bindings (via Cython),
+systems. It provides a stable C ABI, C++20 API, Python bindings (via Cython),
and Rust bindings. The core abstractions are type-erased values
(`Any`/`AnyView`),
reference-counted objects (`Object`/`ObjectRef`), and packed functions
(`Function`).
@@ -75,7 +75,7 @@ cmake --build build_cpp --parallel --config RelWithDebInfo
--target tvm_ffi_shar
### Prerequisites
-- Python 3.9+, C++17 compiler, CMake 3.26+, Ninja
+- Python 3.9+, C++20 compiler, CMake 3.26+, Ninja
- Submodules: `git submodule update --init --recursive`
## Testing
diff --git a/CMakeLists.txt b/CMakeLists.txt
index bf14bbb3..2cd9dcfb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -39,7 +39,7 @@ include(${CMAKE_CURRENT_LIST_DIR}/cmake/Utils/Library.cmake)
# linking
add_library(tvm_ffi_header INTERFACE)
add_library(tvm_ffi::header ALIAS tvm_ffi_header)
-target_compile_features(tvm_ffi_header INTERFACE cxx_std_17)
+target_compile_features(tvm_ffi_header INTERFACE cxx_std_20)
if (CMAKE_CXX_BYTE_ORDER STREQUAL "BIG_ENDIAN")
target_compile_definitions(tvm_ffi_header INTERFACE
TVM_FFI_CMAKE_LITTLE_ENDIAN=0)
@@ -96,7 +96,7 @@ if (TVM_FFI_USE_EXTRA_CXX_API)
endif ()
add_library(tvm_ffi_objs OBJECT ${_tvm_ffi_objs_sources})
-target_compile_features(tvm_ffi_objs PRIVATE cxx_std_17)
+target_compile_features(tvm_ffi_objs PRIVATE cxx_std_20)
set_target_properties(
tvm_ffi_objs
@@ -172,7 +172,7 @@ tvm_ffi_hide_static_linked_lib_symbols(tvm_ffi_shared)
# only for testing purposes
target_sources(tvm_ffi_testing PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/src/ffi/testing/testing.cc")
target_compile_definitions(tvm_ffi_testing PRIVATE
TVM_FFI_DLL_EXPORT_INCLUDE_METADATA=1)
-target_compile_features(tvm_ffi_testing PRIVATE cxx_std_17)
+target_compile_features(tvm_ffi_testing PRIVATE cxx_std_20)
set_target_properties(
tvm_ffi_testing
PROPERTIES CXX_EXTENSIONS OFF
@@ -316,7 +316,7 @@ if (TVM_FFI_BUILD_PYTHON_MODULE)
target_include_directories(
tvm_ffi_cython PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/python/tvm_ffi/cython
)
- target_compile_features(tvm_ffi_cython PRIVATE cxx_std_17)
+ target_compile_features(tvm_ffi_cython PRIVATE cxx_std_20)
target_link_libraries(tvm_ffi_cython PRIVATE tvm_ffi_header)
target_link_libraries(tvm_ffi_cython PRIVATE tvm_ffi_shared)
# link against testing to ensure right unloading order (cython first then
testing)
diff --git a/addons/tvm_ffi_orcjit/CMakeLists.txt
b/addons/tvm_ffi_orcjit/CMakeLists.txt
index a8c04472..a81dda59 100644
--- a/addons/tvm_ffi_orcjit/CMakeLists.txt
+++ b/addons/tvm_ffi_orcjit/CMakeLists.txt
@@ -5,7 +5,7 @@ project(
LANGUAGES C CXX
)
-set(CMAKE_CXX_STANDARD 17)
+set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
diff --git a/addons/tvm_ffi_orcjit/README.md b/addons/tvm_ffi_orcjit/README.md
index 618803e8..6c0b3c98 100644
--- a/addons/tvm_ffi_orcjit/README.md
+++ b/addons/tvm_ffi_orcjit/README.md
@@ -69,7 +69,7 @@ pip install apache-tvm-ffi apache-tvm_ffi_orcjit
#### Prerequisites
-- Python 3.10+, CMake 3.24+, C++17 compiler
+- Python 3.10+, CMake 3.24+, C++20 compiler
The build automatically installs
[mlc-llvm-static](https://pypi.org/project/mlc-llvm-static/)
from PyPI. It supplies LLVM 23.1.1, static zlib/zstd, and the Linux ORC
runtime.
@@ -172,7 +172,7 @@ TVM_FFI_DLL_EXPORT_TYPED_FUNC(add, [](int a, int b) {
});
```
-Compile: `clang++ -std=c++17 -fPIC -O2 -c -o example.o example.cc`
+Compile: `clang++ -std=c++20 -fPIC -O2 -c -o example.o example.cc`
### Pure C (all platforms including Windows)
diff --git a/addons/tvm_ffi_orcjit/examples/quick-start/CMakeLists.txt
b/addons/tvm_ffi_orcjit/examples/quick-start/CMakeLists.txt
index 458f7fdd..969771f3 100644
--- a/addons/tvm_ffi_orcjit/examples/quick-start/CMakeLists.txt
+++ b/addons/tvm_ffi_orcjit/examples/quick-start/CMakeLists.txt
@@ -18,7 +18,7 @@
cmake_minimum_required(VERSION 3.18)
project(tvm_ffi_orcjit_example)
-set(CMAKE_CXX_STANDARD 17)
+set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
diff --git a/addons/tvm_ffi_orcjit/tests/CMakeLists.txt
b/addons/tvm_ffi_orcjit/tests/CMakeLists.txt
index 95776bf4..654db648 100644
--- a/addons/tvm_ffi_orcjit/tests/CMakeLists.txt
+++ b/addons/tvm_ffi_orcjit/tests/CMakeLists.txt
@@ -18,7 +18,7 @@
cmake_minimum_required(VERSION 3.18)
project(tvm_ffi_orcjit_tests)
-set(CMAKE_CXX_STANDARD 17)
+set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
diff --git a/cmake/tvm_ffi-config.cmake b/cmake/tvm_ffi-config.cmake
index 63333da3..3356be1c 100644
--- a/cmake/tvm_ffi-config.cmake
+++ b/cmake/tvm_ffi-config.cmake
@@ -43,12 +43,12 @@ execute_process(
message(STATUS "Finding libfiles ${tvm_ffi_LIB_FILES}")
add_library(tvm_ffi::header INTERFACE IMPORTED)
-target_compile_features(tvm_ffi::header INTERFACE cxx_std_17)
+target_compile_features(tvm_ffi::header INTERFACE cxx_std_20)
target_include_directories(tvm_ffi::header INTERFACE "${tvm_ffi_INCLUDE_DIR}")
target_include_directories(tvm_ffi::header INTERFACE
"${tvm_ffi_DLPACK_INCLUDE_DIR}")
add_library(tvm_ffi::shared SHARED IMPORTED)
-target_compile_features(tvm_ffi::shared INTERFACE cxx_std_17)
+target_compile_features(tvm_ffi::shared INTERFACE cxx_std_20)
if (WIN32)
set_target_properties(tvm_ffi::shared PROPERTIES IMPORTED_IMPLIB
"${tvm_ffi_LIB_FILES}")
diff --git a/docs/conf.py b/docs/conf.py
index 2bae0541..17eb7e74 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -91,7 +91,7 @@ PREDEFINED += TVM_FFI_DLL= TVM_FFI_DLL_EXPORT=
TVM_FFI_INLINE= \
TVM_FFI_EXTRA_CXX_API= TVM_FFI_WEAK=
TVM_FFI_DOXYGEN_MODE \
TVM_FFI_COLD_CODE= \
TVM_FFI_PREDICT_FALSE(x)=x TVM_FFI_PREDICT_TRUE(x)=x
\
- __cplusplus=201703
+ __cplusplus=202002L
EXCLUDE_SYMBOLS += *detail* *TypeTraits* std \
*use_default_type_traits_v* *is_optional_type_v*
*operator* \
tvm::ffi::reflection::default_
tvm::ffi::reflection::default_factory
diff --git a/docs/dev/source_build.rst b/docs/dev/source_build.rst
index 31f692b4..05bee04b 100644
--- a/docs/dev/source_build.rst
+++ b/docs/dev/source_build.rst
@@ -28,9 +28,9 @@ This guide covers two common workflows:
:class: tip
- Python: 3.9 or newer
- - Compiler: C++17-capable toolchain
+ - Compiler: C++20-capable toolchain
- - Linux: GCC or Clang with C++17 support
+ - Linux: GCC or Clang with C++20 support
- macOS: Apple Clang (via Xcode Command Line Tools)
- Windows: MSVC (Visual Studio 2019 or 2022, x64)
diff --git a/docs/get_started/quickstart.rst b/docs/get_started/quickstart.rst
index cd9adce6..a2f87e8b 100644
--- a/docs/get_started/quickstart.rst
+++ b/docs/get_started/quickstart.rst
@@ -36,7 +36,7 @@ We can build a single shared library that works across:
:name: prerequisite
- Python: 3.9 or newer
- - Compiler: C++17-capable toolchain (GCC/Clang/MSVC)
+ - Compiler: C++20-capable toolchain (GCC/Clang/MSVC)
- Optional ML frameworks for testing: NumPy, PyTorch, JAX, CuPy,
PaddlePaddle
- CUDA: Any modern version (if you want to try the CUDA part)
- TVM-FFI installed via:
diff --git a/docs/guides/cubin_launcher.rst b/docs/guides/cubin_launcher.rst
index 386ca168..e4a5b91f 100644
--- a/docs/guides/cubin_launcher.rst
+++ b/docs/guides/cubin_launcher.rst
@@ -249,7 +249,7 @@ For more advanced use cases or non-CMake build systems, you
can use the Python c
.. code-block:: bash
# Step 1: Compile C++ source to object file
- g++ -c -fPIC -std=c++17 -I/path/to/tvm-ffi/include mycode.cc -o mycode.o
+ g++ -c -fPIC -std=c++20 -I/path/to/tvm-ffi/include mycode.cc -o mycode.o
# Step 2: Embed CUBIN into the object file
python -m tvm_ffi.utils.embed_cubin \
diff --git a/docs/packaging/cpp_tooling.rst b/docs/packaging/cpp_tooling.rst
index f49b5363..3c1b216a 100644
--- a/docs/packaging/cpp_tooling.rst
+++ b/docs/packaging/cpp_tooling.rst
@@ -26,7 +26,7 @@ see :doc:`../get_started/quickstart`.
.. admonition:: Prerequisite
:class: hint
- - Compiler: C++17-capable toolchain (GCC/Clang/MSVC)
+ - Compiler: C++20-capable toolchain (GCC/Clang/MSVC)
- CMake: 3.18 or newer
- TVM-FFI installed via
diff --git
a/examples/cubin_launcher/embedded_cubin/include_bin2c/CMakeLists.txt
b/examples/cubin_launcher/embedded_cubin/include_bin2c/CMakeLists.txt
index f825878b..f3e919c8 100644
--- a/examples/cubin_launcher/embedded_cubin/include_bin2c/CMakeLists.txt
+++ b/examples/cubin_launcher/embedded_cubin/include_bin2c/CMakeLists.txt
@@ -18,7 +18,7 @@
cmake_minimum_required(VERSION 3.27)
project(embedded_cubin_example LANGUAGES CXX CUDA)
-set(CMAKE_CXX_STANDARD 17)
+set(CMAKE_CXX_STANDARD 20)
set(CMAKE_TVM_FFI_CUBIN_LAUNCHER_USE_DRIVER_API
OFF
diff --git a/include/tvm/ffi/extra/cuda/cubin_launcher.h
b/include/tvm/ffi/extra/cuda/cubin_launcher.h
index d384ce43..6082cd7d 100644
--- a/include/tvm/ffi/extra/cuda/cubin_launcher.h
+++ b/include/tvm/ffi/extra/cuda/cubin_launcher.h
@@ -88,7 +88,7 @@ namespace ffi {
* nvcc --cubin -arch=sm_75 kernel.cu -o kernel.cubin
*
* # Step 2: Compile C++ source to object file
- * g++ -c -fPIC -std=c++17 -I/path/to/tvm-ffi/include mycode.cc -o mycode.o
+ * g++ -c -fPIC -std=c++20 -I/path/to/tvm-ffi/include mycode.cc -o mycode.o
*
* # Step 3: Embed CUBIN using Python utility
* python -m tvm_ffi.utils.embed_cubin \
diff --git a/include/tvm/ffi/function.h b/include/tvm/ffi/function.h
index 919125d2..d4068255 100644
--- a/include/tvm/ffi/function.h
+++ b/include/tvm/ffi/function.h
@@ -136,7 +136,8 @@ class FunctionObj : public Object, public
TVMFFIFunctionCell {
protected:
/*! \brief Make default constructor protected. */
- FunctionObj() {}
+ // Keep value-initialization from zero-initializing the function cell.
+ FunctionObj() {} // NOLINT(modernize-use-equals-default)
friend class Function;
private:
diff --git a/python/tvm_ffi/config.py b/python/tvm_ffi/config.py
index 15a53d3e..1d3d2f66 100644
--- a/python/tvm_ffi/config.py
+++ b/python/tvm_ffi/config.py
@@ -78,7 +78,7 @@ def __main__() -> None: # noqa: PLR0912
if args.cxxflags:
include_dir = libinfo.find_include_path()
dlpack_include_dir = libinfo.find_dlpack_include_path()
- print(f"-I{include_dir} -I{dlpack_include_dir} -std=c++17")
+ print(f"-I{include_dir} -I{dlpack_include_dir} -std=c++20")
if args.cflags:
include_dir = libinfo.find_include_path()
dlpack_include_dir = libinfo.find_dlpack_include_path()
diff --git a/python/tvm_ffi/cpp/extension.py b/python/tvm_ffi/cpp/extension.py
index f37f279e..e729b2f2 100644
--- a/python/tvm_ffi/cpp/extension.py
+++ b/python/tvm_ffi/cpp/extension.py
@@ -462,7 +462,7 @@ def _generate_ninja_build( # noqa: PLR0915, PLR0912
tvm_ffi_lib_name = tvm_ffi_lib.stem
if IS_WINDOWS:
default_cflags = ["/O2", "/MD"]
- default_cxxflags = ["/std:c++17", "/O2", "/MD", "/EHsc"]
+ default_cxxflags = ["/std:c++20", "/O2", "/MD", "/EHsc"]
_win_warnings = [
"/wd4819",
"/wd4251",
@@ -479,7 +479,7 @@ def _generate_ninja_build( # noqa: PLR0915, PLR0912
default_cxxflags += _win_warnings
# nvcc forwards its own -std and -O to cl for the host pass, as it
does to gcc.
# /MD matches the C++ objects: cl's default /MT fails a mixed link
(LNK2038).
- default_cuda_cflags = ["-Xcompiler", "/MD", "-std=c++17", "-O2"]
+ default_cuda_cflags = ["-Xcompiler", "/MD", "-std=c++20", "-O2"]
default_ldflags = [
"/DLL",
_windows_argument(f"/LIBPATH:{tvm_ffi_lib_path}"),
@@ -493,8 +493,8 @@ def _generate_ninja_build( # noqa: PLR0915, PLR0912
]
else:
default_cflags = ["-fPIC", "-O2"]
- default_cxxflags = ["-std=c++17", "-fPIC", "-O2"]
- default_cuda_cflags = ["-std=c++17", "-O2"]
+ default_cxxflags = ["-std=c++20", "-fPIC", "-O2"]
+ default_cuda_cflags = ["-std=c++20", "-O2"]
default_ldflags = ["-shared", f"-L{tvm_ffi_lib_path}", "-ltvm_ffi"]
if with_hip:
@@ -949,8 +949,8 @@ def build_inline( # noqa: PLR0913
The extra compiler flags for C++ compilation.
The default flags are:
- - On Linux/macOS: ['-std=c++17', '-fPIC', '-O2']
- - On Windows: ['/std:c++17', '/O2']
+ - On Linux/macOS: ['-std=c++20', '-fPIC', '-O2']
+ - On Windows: ['/std:c++20', '/O2']
extra_cuda_cflags
The extra compiler flags for CUDA compilation.
@@ -1179,8 +1179,8 @@ def load_inline( # noqa: PLR0913
The extra compiler flags for C++ compilation.
The default flags are:
- - On Linux/macOS: ['-std=c++17', '-fPIC', '-O2']
- - On Windows: ['/std:c++17', '/O2']
+ - On Linux/macOS: ['-std=c++20', '-fPIC', '-O2']
+ - On Windows: ['/std:c++20', '/O2']
extra_cuda_cflags
The extra compiler flags for CUDA compilation.
@@ -1347,17 +1347,17 @@ def build( # noqa: PLR0913
Extra compiler flags applied to both C and C++ compilation.
The C++ default flags are:
- - On Linux/macOS: ['-std=c++17', '-fPIC', '-O2']
- - On Windows: ['/std:c++17', '/MD', '/O2']
+ - On Linux/macOS: ['-std=c++20', '-fPIC', '-O2']
+ - On Windows: ['/std:c++20', '/MD', '/O2']
- The C default flags omit ``-std=c++17`` and ``/EHsc``.
+ The C default flags omit ``-std=c++20`` and ``/EHsc``.
extra_cuda_cflags
The extra compiler flags for CUDA compilation.
The default flags are:
- - ['-Xcompiler', '-fPIC', '-std=c++17', '-O2'] (Linux/macOS)
- - ['-Xcompiler', '/MD', '-std=c++17', '-O2'] (Windows)
+ - ['-Xcompiler', '-fPIC', '-std=c++20', '-O2'] (Linux/macOS)
+ - ['-Xcompiler', '/MD', '-std=c++20', '-O2'] (Windows)
extra_ldflags
The extra linker flags.
@@ -1505,15 +1505,15 @@ def load( # noqa: PLR0913
The extra compiler flags for C++ compilation.
The default flags are:
- - On Linux/macOS: ['-std=c++17', '-fPIC', '-O2']
- - On Windows: ['/std:c++17', '/MD', '/O2']
+ - On Linux/macOS: ['-std=c++20', '-fPIC', '-O2']
+ - On Windows: ['/std:c++20', '/MD', '/O2']
extra_cuda_cflags
The extra compiler flags for CUDA compilation.
The default flags are:
- - ['-Xcompiler', '-fPIC', '-std=c++17', '-O2'] (Linux/macOS)
- - ['-Xcompiler', '/MD', '-std=c++17', '-O2'] (Windows)
+ - ['-Xcompiler', '-fPIC', '-std=c++20', '-O2'] (Linux/macOS)
+ - ['-Xcompiler', '/MD', '-std=c++20', '-O2'] (Windows)
extra_ldflags
The extra linker flags.
diff --git a/python/tvm_ffi/dataclasses/gen_abi_cpp.py
b/python/tvm_ffi/dataclasses/gen_abi_cpp.py
index 50be13a2..d5b358b9 100644
--- a/python/tvm_ffi/dataclasses/gen_abi_cpp.py
+++ b/python/tvm_ffi/dataclasses/gen_abi_cpp.py
@@ -697,7 +697,7 @@ def gen_abi_cpp(type_keys: str | Sequence[str]) -> str:
Returns
-------
str
- Deterministic C++17 header source. The source performs lookup only;
+ Deterministic C++20 header source. The source performs lookup only;
it does not register, compile, load, or allocate any type.
"""
diff --git a/tests/cpp/CMakeLists.txt b/tests/cpp/CMakeLists.txt
index ad8c6c87..dc17c92c 100644
--- a/tests/cpp/CMakeLists.txt
+++ b/tests/cpp/CMakeLists.txt
@@ -6,7 +6,7 @@ if (TVM_FFI_USE_EXTRA_CXX_API)
endif ()
add_executable(tvm_ffi_tests ${_test_sources})
-target_compile_features(tvm_ffi_tests PRIVATE cxx_std_17)
+target_compile_features(tvm_ffi_tests PRIVATE cxx_std_20)
set_target_properties(
tvm_ffi_tests
diff --git a/tests/cpp/extra/test_json_parser.cc
b/tests/cpp/extra/test_json_parser.cc
index 49d2c34c..6c0d90b2 100644
--- a/tests/cpp/extra/test_json_parser.cc
+++ b/tests/cpp/extra/test_json_parser.cc
@@ -144,7 +144,7 @@ TEST(JSONParser, String) {
// test unicode code point
EXPECT_EQ(json::Parse("\"\\u0041\"").cast<String>(), "A");
// test unicode surrogate pair
- EXPECT_EQ(json::Parse("\"\\uD83D\\uDE04hello\"").cast<String>(),
u8"\U0001F604hello");
+ EXPECT_EQ(json::Parse("\"\\uD83D\\uDE04hello\"").cast<String>(),
"\xF0\x9F\x98\x84hello");
}
TEST(JSONParser, WrongString) {
@@ -281,13 +281,13 @@ TEST(JSONParser, WrongEmptyAndMinimalInputs) {
TEST(JSONParser, UnicodeEdgeCases) {
// Test various unicode characters
EXPECT_EQ(json::Parse("\"\\u0000\"").cast<String>(), std::string("\0", 1));
- // replace using \U to avoid encoding issues
- EXPECT_EQ(json::Parse("\"\\u00FF\"").cast<String>(), u8"\U000000FF");
- EXPECT_EQ(json::Parse("\"\\u4E2D\\u6587\"").cast<String>(),
u8"\U00004E2D\U00006587");
+ // Use explicit UTF-8 bytes: C++20 u8 literals have char8_t elements, while
String uses char.
+ EXPECT_EQ(json::Parse("\"\\u00FF\"").cast<String>(), "\xC3\xBF");
+ EXPECT_EQ(json::Parse("\"\\u4E2D\\u6587\"").cast<String>(),
"\xE4\xB8\xAD\xE6\x96\x87");
// Test multiple surrogate pairs
EXPECT_EQ(json::Parse("\"\\uD83D\\uDE00\\uD83D\\uDE01\"").cast<String>(),
- u8"\U0001F600\U0001F601");
+ "\xF0\x9F\x98\x80\xF0\x9F\x98\x81");
}
TEST(JSONParser, RawUTF8Bytes) {
@@ -357,10 +357,10 @@ TEST(JSONParser, MixedDataTypes) {
{"boolean_false", false},
{"integer", 42},
{"negative_integer", -42},
- {"float", 3.14159},
+ {"float", 3.14159}, // NOLINT(modernize-use-std-numbers): match the
JSON decimal exactly.
{"scientific", 1.23e-4},
{"string", "hello world"},
- {"unicode_string", u8"Hello \U00004E16\U0000754C \U0001F30D"},
+ {"unicode_string", "Hello \xE4\xB8\x96\xE7\x95\x8C \xF0\x9F\x8C\x8D"},
{"empty_string", ""},
{"empty_array", json::Array{}},
{"empty_object", json::Object{}},
diff --git a/tests/python/test_libinfo.py b/tests/python/test_libinfo.py
index d58e8a9c..387b0cb7 100644
--- a/tests/python/test_libinfo.py
+++ b/tests/python/test_libinfo.py
@@ -89,7 +89,7 @@ def test_libs_reports_link_target() -> None:
def test_cxxflags_include_paths_and_standard() -> None:
include_dir = libinfo.find_include_path()
dlpack_dir = libinfo.find_dlpack_include_path()
- assert _stdout_for("--cxxflags") == f"-I{include_dir} -I{dlpack_dir}
-std=c++17"
+ assert _stdout_for("--cxxflags") == f"-I{include_dir} -I{dlpack_dir}
-std=c++20"
def test_cflags_include_paths() -> None: