This is an archive of the discontinued LLVM Phabricator instance.

[Clang] Add `-funstable` flag to enable unstable and experimental features

Authored by egorzhdan on Feb 18 2022, 1:11 PM.



This new flag enables __has_feature(cxx_unstable) that would replace libc++ macros for individual unstable/experimental features, e.g. _LIBCPP_HAS_NO_INCOMPLETE_RANGES or _LIBCPP_HAS_NO_INCOMPLETE_FORMAT.

This would make it easier and more convenient to opt-in into all libc++ unstable features at once.

Diff Detail

Event Timeline

egorzhdan created this revision.Feb 18 2022, 1:11 PM
egorzhdan requested review of this revision.Feb 18 2022, 1:11 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 18 2022, 1:11 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
zoecarver accepted this revision.Feb 21 2022, 9:23 AM

This looks great, thanks Egor!

This revision is now accepted and ready to land.Feb 21 2022, 9:23 AM
var-const accepted this revision.Feb 22 2022, 5:53 PM
This revision was landed with ongoing or failed builds.Mar 1 2022, 4:35 AM
This revision was automatically updated to reflect the committed changes.
ldionne added subscribers: Restricted Project, Restricted Project, rsmith, CaseyCarter.Mar 1 2022, 11:12 AM

Oops, this seems to have happened while I was on vacation. I wanted to have a wider discussion here before shipping the patch. Let's have it now and we can make post-commit changes depending on where the discussion leads.

So, what we're trying to achieve here is to provide a user-controlled flag to enable things that are not "production ready". This includes:

  • TSes (since we remove them after shipping the "real thing" for two releases)
  • Standardized features that we implement only in part (for example <ranges>, where we don't yet have a fully coherent thing to ship, so we'd rather not pretend that we ship it in a stable way yet)
  • Standardized features that we know for a fact are about to be broken by the Standard itself (this happened with <ranges> and <format> recently)

The problem this solves is that in the current state of things, we end up simply not shipping those features at all by fear that users are going to start depending on them, and then we'll break them. We want to be able to ship these features without actually committing to their stability.

We considered a few alternative directions for this patch, which we rejected:

  • -fexperimental: We decided not to go with this because we wanted to convey the fact that said features were unstable, and hence dangerous to use in production code
  • -std=c++latest: This would be close to what MSVC does. We decided not to go down this route because we felt like it didn't properly convey the notion of instability. Instead, we felt that -std=c++latest could/should be a simple alias for whatever the latest known standard is (which is not part of this patch).

Does anyone have thoughts?


The documentation of this option should be way more beefy. Something like:

Enable unstable and experimental language and library features.

This option enables various language and library features that are either experimental (also known as TSes), or have been standardized but are not stable yet. This option should not be used in production code, since neither ABI nor API stability are guaranteed.

We should also provide documentation inside clang/docs/ClangCommandLineReference.rst.


We should also be adding -lc++experimental if the standard library is libc++.

Thanks for implementing this @egorzhdan! Thanks @ldionne for the notification.

-funstable is an option that controls multiple flags therefore I think it would be good to have a separate flag to opt-in for unstable/incomplete libc++ features. That makes it easier to _only_ opt-in to these features. Then -funstable can also enable that flag. Maybe -funstable-libc++ and adding a feature libcxx_unstable that we can use in libc++ to detect that the flag was set.




Is this option still useful? In LLVM 14 the <coroutine> header is no longer experimental. The experimental header will soon be removed.

Apologies for landing this too quickly! I'll adjust this logic in a separate patch:

-funstable is an option that controls multiple flags therefore I think it would be good to have a separate flag to opt-in for unstable/incomplete libc++ features. That makes it easier to _only_ opt-in to these features.

@Mordante could you please elaborate a little bit, are you proposing a separate flag that would be equivalent to -Xcc -funstable (essentially to enable LangOpts.Unstable but not the rest of the flags) and have a different spelling to indicate that it is specific to libc++?

Herald added a project: Restricted Project. · View Herald TranscriptMar 7 2022, 11:37 AM