Skip to content

Update the minimum C++ version to C++17 #5158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,7 @@ for detailed advice.

#### C++ language version

**C++11.**

NOTE: The code does not yet fully conform to this, and some files require C++17.
**C++17.**

Rationale: This is a compromise between being compatible with older, proprietary
toolchains, and having access to relatively modern C++ features.
Expand Down
8 changes: 3 additions & 5 deletions docs/source/getting-started-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,11 @@ also work in similar environments.
- We recommend `conda` as it provides cross-language
support and integrates smoothly with `pip` (Python's built-in package manager)
- Otherwise, Python's built-in virtual environment manager `python venv` is a good alternative.
* `g++` version 8 or higher, `clang++` version 8 or higher, or another
C++17-compatible toolchain that supports GNU C-style [statement
expressions](https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html) (`({ ...
})` syntax).
* `g++` version 7 or higher, `clang++` version 5 or higher, or another
C++17-compatible toolchain.

Note that the cross-compilable core runtime code supports a wider range of
toolchains, down to C++11. See the [Runtime Overview](./runtime-overview.md) for
toolchains, down to C++17. See the [Runtime Overview](./runtime-overview.md) for
portability details.

## Quick Setup: Colab/Jupyter Notebook Prototype
Expand Down
2 changes: 1 addition & 1 deletion docs/source/runtime-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ can build it for a wide variety of target systems.

#### C++ Language Considerations

* The code is C++11-compatible to work with older toolchains.
* The code is C++17-compatible to work with older toolchains.
* The runtime does not use exceptions or RTTI, although it is not antagonistic
to them.
* The code is compatible with GCC and Clang, and has also been built with
Expand Down
31 changes: 23 additions & 8 deletions runtime/platform/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,32 @@

#pragma once

// Compiler support checks.
/*
* Compiler support checks. Follows the logic used by pytorch/c10/util/C++17.h
* but may support older versions.
*/

// https://gcc.gnu.org/projects/cxx-status.html#cxx17
#if !defined(__clang__) && !defined(_MSC_VER) && defined(__GNUC__) && \
__GNUC__ < 7
#error \
"You're trying to build ExecuTorch with a too old version of GCC. We need GCC 7 or later."
#endif

// https://clang.llvm.org/cxx_status.html#cxx17
#if defined(__clang__) && __clang_major__ < 5
#error \
"You're trying to build ExecuTorch with a too old version of Clang. We need Clang 5 or later."
#endif

#if !defined(__cplusplus)
#error ExecuTorch must be compiled using a C++ compiler.
#if (defined(_MSC_VER) && (!defined(_MSVC_LANG) || _MSVC_LANG < 201703L)) || \
(!defined(_MSC_VER) && __cplusplus < 201703L)
#error "You need C++17 to compile ExecuTorch"
#endif

#if __cplusplus < 201103L && (!defined(_MSC_VER) || _MSC_VER < 1600) && \
(!defined(__GNUC__) || \
(__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__ < 40400))
#error ExecuTorch must use a compiler supporting at least the C++11 standard.
#error __cplusplus _MSC_VER __GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__
#if defined(_WIN32) && (defined(min) || defined(max))
#error \
"Macro clash with min and max -- define NOMINMAX when compiling your program on Windows"
#endif

/*
Expand Down
Loading