Summary
We propose to add an internal -cc1 -fno-coroutines
compiler flag for disabling coroutines in -std=c++20
for Clang 17.
I propose to not advertise this configuration to the users and keeping it a -cc1
option to have the ability to remove it in the future.
Motivation
At Google, we build code with a variety of toolchains. Most code is only built with the main toolchain (Clang) that is close to LLVM head. However, some code also builds with other toolchains based on LLVM releases (most notably, Apple Clang).
We want to have the ability to enable C++20 without coroutines in the Clang 17-based toolchains .
This is motivated by unaddressed compiler bugs in coroutines, there is a list in ā D156247 [Clang] Add a warning on uses of coroutine keywords.
The bugs are niche and are not blockers to using coroutines for most users. However, because of the large number of affected C++ users that we support, we are overly cautious of any miscompiles and would like to have the ability to turn off the feature if something goes wrong.
Related work
GCC has -fno-coroutines
available as a user option it works as expected, disabling the feature.
Costs
This adds a new language dialect to Clang (C++20 without coroutines). Implementation in the compiler is simple, see ā D156247 [Clang] Add a warning on uses of coroutine keywords.
libc++ may choose to show an error via preprocessor if <coroutine>
is included, but the coroutine implementation macro is not defined (this is probably the right thing anyway as C++17).
For future standards (C++23, C++26), more standard headers (e.g. <generator>
) will start depending on <coroutine>
and users of -cc1 -fno-coroutines
will see failures on the parts of the STL that depend on <coroutine>
.
However, libc++ may also choose to not add any extra error code, in which case the users will bear the consequences of this feature will have to deal with unclear error messages.
Users of the feature will need to workaround any problems in this configuration.
Complications
- This proposal is very late in the release timeline and should have been submitted earlier. I am sorry for not bringing this up a month ago, but the idea came up in the discussions early last week.
- Support costs, see above.
Alternatives considered
Local downstream patch
Because we do not control the source code of the toolchains in questions, we do not have the ability to make this a downstream patch.
Implement this as a linter check
We cannot enforce this as a linter check (through clang-tidy or other means) because we donāt have the capacity to identify all code compiled by the toolchains in questions (this is a limitation of our internal infrastructure).
Driver flag instead of compiler flag
User-visible flags (i.e. no -cc1
) have a higher quality bar and impose more support costs. Given the niche nature of the problems this proposal tries to solve (specific to Google, specific to a single feature and to a single compiler release) and short timelines to the release, I believe we should not consider a public flag.
Compiler warning
Marking all uses of a standard feature does not seem like a good fit for a compiler warning.