[PATCH] D67663: [Compiler] Fix LLVM_NODISCARD for GCC

Dávid Bolvanský via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 24 06:59:20 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL372761: [Compiler] Fix LLVM_NODISCARD for GCC (authored by xbolva00, committed by ).
Herald added subscribers: llvm-commits, kristina.
Herald added a project: LLVM.

Changed prior to commit:
  https://reviews.llvm.org/D67663?vs=220693&id=221538#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D67663

Files:
  llvm/trunk/include/llvm/Support/Compiler.h


Index: llvm/trunk/include/llvm/Support/Compiler.h
===================================================================
--- llvm/trunk/include/llvm/Support/Compiler.h
+++ llvm/trunk/include/llvm/Support/Compiler.h
@@ -137,10 +137,18 @@
 #endif
 
 /// LLVM_NODISCARD - Warn if a type or return value is discarded.
+
+// Use the 'nodiscard' attribute in C++17 or newer mode.
 #if __cplusplus > 201402L && LLVM_HAS_CPP_ATTRIBUTE(nodiscard)
 #define LLVM_NODISCARD [[nodiscard]]
 #elif LLVM_HAS_CPP_ATTRIBUTE(clang::warn_unused_result)
 #define LLVM_NODISCARD [[clang::warn_unused_result]]
+// Clang in C++14 mode claims that it has the 'nodiscard' attribute, but also
+// warns in the pedantic mode that 'nodiscard' is a C++17 extension (PR33518).
+// Use the 'nodiscard' attribute in C++14 mode only with GCC.
+// TODO: remove this workaround when PR33518 is resolved.
+#elif defined(__GNUC__) && LLVM_HAS_CPP_ATTRIBUTE(nodiscard)
+#define LLVM_NODISCARD [[nodiscard]]
 #else
 #define LLVM_NODISCARD
 #endif


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67663.221538.patch
Type: text/x-patch
Size: 1004 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190924/b22901d8/attachment.bin>


More information about the llvm-commits mailing list