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

Arthur O'Dwyer via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 4 10:38:48 PDT 2018


Quuxplusone added a comment.

In https://reviews.llvm.org/D45179#1056706, @lebedev.ri wrote:

> gcc does not silence the warning produced by
>  these attributes via `(void)` cast, unless it's `[[nodiscard]]` attribute :/
>  [...] So until they fix that (they will fix that right? :)),
>  we can only support `_LIBCPP_FORCE_NODISCARD` for clang compilers.


The GCC warn_unused_result issue is https://gcc.gnu.org/bugzilla/show_bug.cgi?id=25509 and also https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425 . I would certainly love for them to fix it, but the sentiment expressed in those bug reports is "no! never! we love being broken!". :/
I re-suggest my idea that perhaps libc++ should respect the user's choice to pass `-D_LIBCPP_NODISCARD=__attribute__((warn_unused_result))` on the GCC command line. This would make your patch only one line longer than it is right now...


Repository:
  rCXX libc++

https://reviews.llvm.org/D45179





More information about the cfe-commits mailing list