[Compiler] Fix LLVM_NODISCARD for GCC
commit16d1916c998722664a67aee0e809263a0eea45a2
authorDavid Bolvansky <david.bolvansky@gmail.com>
Tue, 24 Sep 2019 14:01:14 +0000 (24 14:01 +0000)
committerDavid Bolvansky <david.bolvansky@gmail.com>
Tue, 24 Sep 2019 14:01:14 +0000 (24 14:01 +0000)
tree9a85bc69555ba8cf179fb0588f86b62212ab491e
parentfc4a759c680eeb91fb7f18b37281ba3b9febc298
[Compiler] Fix LLVM_NODISCARD for GCC

Summary:
This branch is currently dead since we don't use C++17.
 #if __cplusplus > 201402L && LLVM_HAS_CPP_ATTRIBUTE(nodiscard)
 #define LLVM_NODISCARD [[nodiscard]]

This branch is Clang-only.
 #elif LLVM_HAS_CPP_ATTRIBUTE(clang::warn_unused_result)
 #define LLVM_NODISCARD [[clang::warn_unused_result]]

While we could use gnu variant  [[gnu::warn_unused_result]], it is not ideal because it works only on functions.
/home/xbolva00/LLVM/llvm/include/llvm/ADT/ArrayRef.h:41:24: warning: â€˜warn_unused_result’ attribute only applies to function types [-Wattributes]

GCC (checked 5,6,7,8) seems to enable [[nodiscard]] even in C++14 mode and does not produce warnings that nodiscard is C++17 feature. but Clang does - but we do not reach it due the code above. So it affects only GCC and does what we want.

Reviewers: jfb, rsmith, echristo, aaron.ballman

Reviewed By: aaron.ballman

Subscribers: MaskRay, dexonsmith

Differential Revision: https://reviews.llvm.org/D67663

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@372761 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/Support/Compiler.h