[PATCH] D45179: [libc++] Add _LIBCPP_FORCE_NODISCARD define to force-enable nodiscard in pre-C++17

Roman Lebedev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 25 02:01:01 PDT 2018


lebedev.ri added inline comments.


================
Comment at: test/libcxx/diagnostics/force_nodiscard.pass.cpp:16
+// MODULES_DEFINES: _LIBCPP_FORCE_NODISCARD
+#define _LIBCPP_DISABLE_NODISCARD_AFTER_CXX17
+#define _LIBCPP_FORCE_NODISCARD
----------------
lebedev.ri wrote:
> Quuxplusone wrote:
> > What is the purpose of `_LIBCPP_DISABLE_NODISCARD_AFTER_CXX17`? I guess I could understand a blanket opt-in "please don't warn me about discarded [[nodiscard]] results"; but that should be (and is) spelled `-Wno-unused-result`, and it has nothing to do with C++17.
> > 
> > I like how this patch defines `_LIBCPP_NODISCARD` in non-C++17 modes; that's going to be very useful. But I think all these opt-in mechanisms are confusing and not-helpful.
> > 
> > If we must have an opt-in/out mechanism (which I don't believe we do), please consider adding the following two lines to `<__config>` and removing the rest:
> > 
> >     #ifdef _LIBCPP_NODISCARD
> >         // the user has given us their preferred spelling; use it unconditionally
> >     #elif __has_cpp_attribute(nodiscard) && _LIBCPP_STD_VER > 17
> >         [... etc etc ...]
> > 
> > If we must have an opt-in/out mechanism (which I don't believe we do)
> 
> Yes, we do.
> Opt-out is pre-existing, and removing it would be an [unacceptable] regression.
> Opt-in is an enhancement. Of course, it would be nice to always default it to on,
> but as it was disscussed with @mclow.lists, this is simply not going to happen.
> This is the best we'll get.
> 
> ```
> #ifdef _LIBCPP_NODISCARD
>     // the user has given us their preferred spelling; use it unconditionally
> ```
> So you propose to shift the burden of picking which define to use to each and every
> libc++ user (who wants to enable nodiscard attribute for pre-C++17/whatever) out there?
> I really don't see how that would be better.
I tried to do that, but completely failed to come up with testing, so i'm not going to do this here, sorry.


Repository:
  rCXX libc++

https://reviews.llvm.org/D45179





More information about the cfe-commits mailing list