JEP draft: Compile the JDK as C++17
Author | Julian Waters |
Type | Infrastructure |
Scope | Implementation |
Status | Closed / Rejected |
Relates to | JEP 347: Enable C++14 Language Features |
Reviewed by | Kim Barrett |
Endorsed by | Kim Barrett |
Created | 2023/06/17 05:24 |
Updated | 2023/08/14 19:11 |
Issue | 8310260 |
Summary
Compile the JDK's C++ source code as the C++17 language.
Goals
Since JDK 16, the language features used by C++ code in the JDK have been set to the C++14 language standard. The purpose of this JEP is to formally allow C++ source code changes within the JDK to use C++17 language features, and to give specific guidance about which of those features may be used in HotSpot code.
Non-Goals
This JEP does not propose any usage or style changes for C++ code in the JDK that is outside of HotSpot. HotSpot's Style Guide has already been adapted for C++14 previously and should require only minimal changes.
Description
Changes to the Build System
Microsoft Visual C/C++ Compiler: Visual Studio 2019 is required for JDK 17 and above. (Earlier versions will be rejected by configure.) Change the existing -std:c++14 flag to -std:c++17 for C++.
Other supported compilers: Replace the -std=c++14 option -std=c++17.
The minimum supported version of gcc is 8
The minimum supported version of clang is 10
Changes to C++ Usage in HotSpot code
The existing restrictions and best-practice recommendations for C++ usage in HotSpot code are based on the C++14 language standard, and described in the HotSpot Style Guide.
Lists of new features for C++17, along with links to their descriptions, can be found in the online documentation for some of the compilers and libraries:
- C++ Standards Support in GCC
- C++ Support in Clang
- Visual C++ Language Conformance
- libstdc++ Status
- libc++ Status
Risks and Assumptions
Code that works with the current specification of C++14 may break when compiled as C++17, or may silently change behaviour without compilation errors due to differing semantics between the language versions.