[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
Wed Apr 10 15:45:06 PDT 2019


ThadHouse created this revision.
Herald added subscribers: llvm-commits, kristina.
Herald added a project: LLVM.

MSVC defaults __cplusplus to an old version, which causes the preprocessor to fallthrough to the clang::xx attribute checks. MSVC see's these and errors intellisense. This checks for MSVC explicitly, and handles the attributes for it separately.


Repository:
  rL LLVM

https://reviews.llvm.org/D60547

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


Index: llvm/include/llvm/Support/Compiler.h
===================================================================
--- llvm/include/llvm/Support/Compiler.h
+++ llvm/include/llvm/Support/Compiler.h
@@ -122,6 +122,11 @@
 /// LLVM_NODISCARD - Warn if a type or return value is discarded.
 #if __cplusplus > 201402L && __has_cpp_attribute(nodiscard)
 #define LLVM_NODISCARD [[nodiscard]]
+// Detect MSVC directly, since __cplusplus still defaults to old version
+#elif _MSVC_LANG >= 201703L
+#define LLVM_NODISCARD [[nodiscard]]
+#elif _MSC_VER
+#define LLVM_NODISCARD
 #elif !__cplusplus
 // Workaround for llvm.org/PR23435, since clang 3.6 and below emit a spurious
 // error when __has_cpp_attribute is given a scoped attribute in C mode.
@@ -242,6 +247,11 @@
 /// LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
 #if __cplusplus > 201402L && __has_cpp_attribute(fallthrough)
 #define LLVM_FALLTHROUGH [[fallthrough]]
+// Detect MSVC directly, since __cplusplus still defaults to old version
+#elif _MSVC_LANG >= 201703L
+#define LLVM_FALLTHROUGH [[fallthrough]]
+#elif _MSC_VER
+#define LLVM_FALLTHROUGH
 #elif __has_cpp_attribute(gnu::fallthrough)
 #define LLVM_FALLTHROUGH [[gnu::fallthrough]]
 #elif !__cplusplus


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60547.194603.patch
Type: text/x-patch
Size: 1229 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190410/0576d115/attachment.bin>


More information about the llvm-commits mailing list