[llvm-dev] Adding [[nodiscard]] to Compiler.h

Chandler Carruth via llvm-dev llvm-dev at lists.llvm.org
Sun Sep 4 16:09:15 PDT 2016


On Sun, Sep 4, 2016 at 3:53 PM Sanjoy Das <sanjoy at playingwithpointers.com>
wrote:

> Hi Chandler,
>
> Chandler Carruth wrote:
>  > My 2 cents: get rid of LLVM_UNUSED_RESULT, and move to LLVM_NODISCARD.
>  >
>  > For compilers that support it, it should be a strict superset of
> features and functionality. The standard feature was
>  > written directly based on the clang warn_unused_result stuff.
>
> Maybe I misunderstood something, but with clang 3.8.1 I cannot write:
>
> int [[clang::nodiscard]] f();
>
> so I'm not sure if LLVM_NODISCARD provides a superset of the functionality.
>

I don't know anything about [[clang::nodiscard]], but I would expect
[[clang::warn_unused_result]]
in C++11 and C++14 to work in all the places and have the same effect as
[[nodiscard]] does in C++17. Here is a recent clang build:

echo -e '[[nodiscard]] int f();\nstruct [[nodiscard]] X {};' | clang
-fsyntax-only -x c++ -std=c++1z -
echo -e '[[clang::warn_unused_result]] int f();\nstruct
[[clang::warn_unused_result]] X {};' | clang -fsyntax-only -x c++
-std=c++11 -

-Chandler
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160904/9f77d00e/attachment-0001.html>


More information about the llvm-dev mailing list