[PATCH] D60547: Add checks for MSVC in LLVM_FALLTHROUGH and LLVM_NODISCARD

Thad House via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 18 15:41:56 PDT 2019


ThadHouse marked an inline comment as done.
ThadHouse added inline comments.


================
Comment at: llvm/include/llvm/Support/Compiler.h:123
 /// LLVM_NODISCARD - Warn if a type or return value is discarded.
 #if __cplusplus > 201402L && __has_cpp_attribute(nodiscard)
 #define LLVM_NODISCARD [[nodiscard]]
----------------
rnk wrote:
> ThadHouse wrote:
> > zturner wrote:
> > > zturner wrote:
> > > > What about just changing this `&&` to an `||`?
> > > Another question: Why is the check for `__cplusplus` even needed?
> > Is there CI for testing against old versions of clang and GCC, to make sure that it doesn't cause a regression. Otherwise yeah I think that would work too. Although I wonder if the original creators had a reason to check a newer c++ version.
> I think we can check `__has_cpp_attribute` without the `__cplusplus` check, or just check `defined(__cplusplus)` if we need to avoid C++ style attributes in C code. I'll test it and try committing that tomorrow.
For MSVC that might not be enough, as it errors if it falls through to the `gnu::***` and `llvm::***` attribute checks. For MSVC even in C++ mode, if `nodiscard` attribute is not found, the checks afterward can't happen either, as they error. And older versions of MSVC will likely error on just the initial `__has_cpp_attribute`, because isn't that new to the standard?


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60547/new/

https://reviews.llvm.org/D60547





More information about the llvm-commits mailing list