Skip to content

Proposal: Upgrade C++ compiler feature level to C++ 17 #112419

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

Open
huoyaoyuan opened this issue Feb 11, 2025 · 7 comments
Open

Proposal: Upgrade C++ compiler feature level to C++ 17 #112419

huoyaoyuan opened this issue Feb 11, 2025 · 7 comments
Labels
area-Infrastructure-coreclr untriaged New issue has not been triaged by the area owner

Comments

@huoyaoyuan
Copy link
Member

huoyaoyuan commented Feb 11, 2025

The coreclr codebase has been using C++ 11 for a long time. Adopting C++ 17 features can help simplifying some code, for example message-less static_assert, or usage of filesystem in non-clr testing code.

It would require all supported configurations to have C++ 17 compatible compiler. Since we have upgraded the CMake requirement to 3.20 which was released in March 2021, it's unlikely to see an environment to have CMake 3.20 but no C++ 17 compiler.

On Windows and Apple OSes we are using latest compilers so there should be less concern. According to https://en.cppreference.com/w/cpp/compiler_support/17 , all C++ 17 language features are supported since GCC 7. RHEL 8 includes GCC 8.x. I couldn't figure out the GCC version included in all distros, but it seems that all our supported distros are having higher GCC version.

/cc @jkoritzinsky @dotnet/distro-maintainers Any comment or blocker on this?

@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Feb 11, 2025
@jkoritzinsky
Copy link
Member

We are also limited by the features of the target rootfs's stdlib, which may be quite out of date (I'm not sure the feature set of the libstdc++ in Ubuntu 18.04). Although given our current guidance, that does only matter for testing code since we recommend against heavy STL usage in product code.

@EgorBo
Copy link
Member

EgorBo commented Feb 12, 2025

Adopting C++ 17 features can help simplifying some code, for example message-less static_assert, or usage of filesystem in non-clr testing code.

Is there anything else we'd benefit from? I think the proposal should include a strong motivation "why"

@huoyaoyuan
Copy link
Member Author

I think the proposal should include a strong motivation "why"

The major benefit should be code simplification, plus some opportunity for taking compiler optimization. I was initially initiated by checking static_assert. I'll try to summarize more cases.

@dviererbe
Copy link
Contributor

In Ubuntu we use Clang to compile .NET. We (Canonical) only build for Ubuntu 22.04+, but Microsoft supports and builds also for Ubuntu 18.04+.

According to https://clang.llvm.org/cxx_status.html:

Clang 5 and later implement all the features of the ISO C++ 2017 standard.

Ubuntu has the following Clang versions (5+):

Ubuntu version available LLVM/Clang versions
18.04 LST (Bionic Beaver) 5, 6 (default), 7, 8, 9, 10
20.04 LTS (Focal Fossa) 6, 7, 8, 9, 10 (default), 11, 12, 18
22.04 LTS (Jammy Jellyfish) 11, 12, 13, 14 (default), 15
24.04 LTS (Noble Numbat) 14, 15, 16, 17, 18 (default), 19
24.10 (Oracular Oriole) 14, 15, 16, 17, 18, 19 (default)
25.04 (Plucky Puffin) 14, 15, 17, 18, 19 (current default), 20 (planned default)

See:

TL;DR: Therefore, upgrading the C++ compiler feature level to C++ 17 should not be an issue for the Ubuntu platform.

@omajid
Copy link
Member

omajid commented Feb 18, 2025

RHEL / CentOS Stream

On RHEL (and CentOS Stream) we also use clang to build .NET. Here are the default versions of clang in each:

RHEL/CentOS Stream version Clang versions
RHEL 8 18
RHEL 9 18
CentOS Stream 10 19

These are new enough that they should support everything .NET needs from C++ 17

Fedora

Fedora version Clang versions
Fedora 40 18
Fedora 41 19
Fedora 42 19
Fedora Rawhide 19

These are new enough that they should support everything .NET needs from C++ 17

@AaronRobinsonMSFT
Copy link
Member

I personally don't see any reason not to move forward in this case.

The major benefit should be code simplification, plus some opportunity for taking compiler optimization. I was initially initiated by checking static_assert. I'll try to summarize more cases.

We should be careful here. The C++ in this code base should be simple. We're not looking to adopt most modern C++ features. There are some APIs that we could benefit from, but they are narrow in scope. An example of a beneficial win from keeping more current would be adoption of the gsl libraries, it only requires C++ 14 which we use in some cases already.

Specific benefits from C++17 itself are things like the fallthrough attribute or some narrow uses of constexpr. Features that we'd likely prefer to avoid are things like std::string_view, __has_include, nested namespaces or the new filesystem APIs.

Keeping as current as possible is a good goal, but it should be in service of staying current and modern rather than grabbing newer C++ features. This is a just a priority thing.

@janvorli
Copy link
Member

janvorli commented Mar 4, 2025

I've just bumped into a case today that would benefit from moving to C++17 too. The if constexpr (condition) in template methods / classes would be useful in my case to make some calls in a template method optional for specific template argument types. There is a way do achieve the same thing in a different way, but the constexpr one would be nice and clean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Infrastructure-coreclr untriaged New issue has not been triaged by the area owner
Projects
Status: No status
Development

No branches or pull requests

7 participants