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

Marshall Clow via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 25 07:19:25 PDT 2018

mclow.lists added inline comments.

Comment at: test/libcxx/diagnostics/force_nodiscard.fail.cpp:22
+_LIBCPP_NODISCARD_AFTER_CXX17 int foo() { return 6; }
lebedev.ri wrote:
> mclow.lists wrote:
> > Shouldn't this be just `_LIBCPP_NODISCARD` ?
> > 
> I don't think so?
> I thought we are intentionally testing the same macro that libc++ is using internally.
Ok, I see what you're saying. 

This test is testing if a function marked `_LIBCPP_NODISCARD_AFTER_CXX17` gives an error if `_LIBCPP_FORCE_NODISCARD` is defined.

But then you need another test, just like this, with `_LIBCPP_NODISCARD int foo() { return 6; }` to make sure that that gives an error as well. (and a passing test, that shows that if you don't opt-in, you get no error)

  rCXX libc++


More information about the cfe-commits mailing list