[PATCH] D57196: Fix error in Visual Studio due to __has_cpp_attribute

Haozhun Jin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 24 15:35:36 PST 2019


haozhun updated this revision to Diff 183418.

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

https://reviews.llvm.org/D57196

Files:
  include/llvm/Support/Compiler.h


Index: include/llvm/Support/Compiler.h
===================================================================
--- include/llvm/Support/Compiler.h
+++ include/llvm/Support/Compiler.h
@@ -38,6 +38,13 @@
 
 #ifndef __has_cpp_attribute
 # define __has_cpp_attribute(x) 0
+# define __has_cpp_attribute_qualified(x) 0
+#elif defined(_MSC_VER)
+// MSVC only allows simple identifier in feature-test macros,
+// and reports IntelliSense error otherwise.
+# define __has_cpp_attribute_qualified(x) 0
+#else
+# define __has_cpp_attribute_qualified __has_cpp_attribute
 #endif
 
 #ifndef __has_builtin
@@ -127,7 +134,7 @@
 // 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.
 #define LLVM_NODISCARD
-#elif __has_cpp_attribute(clang::warn_unused_result)
+#elif __has_cpp_attribute_qualified(clang::warn_unused_result)
 #define LLVM_NODISCARD [[clang::warn_unused_result]]
 #else
 #define LLVM_NODISCARD
@@ -140,7 +147,7 @@
 // The clang-tidy check bugprone-use-after-move recognizes this attribute as a
 // marker that a moved-from object has left the indeterminate state and can be
 // reused.
-#if __has_cpp_attribute(clang::reinitializes)
+#if __has_cpp_attribute_qualified(clang::reinitializes)
 #define LLVM_ATTRIBUTE_REINITIALIZES [[clang::reinitializes]]
 #else
 #define LLVM_ATTRIBUTE_REINITIALIZES
@@ -243,13 +250,13 @@
 /// LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
 #if __cplusplus > 201402L && __has_cpp_attribute(fallthrough)
 #define LLVM_FALLTHROUGH [[fallthrough]]
-#elif __has_cpp_attribute(gnu::fallthrough)
+#elif __has_cpp_attribute_qualified(gnu::fallthrough)
 #define LLVM_FALLTHROUGH [[gnu::fallthrough]]
 #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.
 #define LLVM_FALLTHROUGH
-#elif __has_cpp_attribute(clang::fallthrough)
+#elif __has_cpp_attribute_qualified(clang::fallthrough)
 #define LLVM_FALLTHROUGH [[clang::fallthrough]]
 #else
 #define LLVM_FALLTHROUGH


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57196.183418.patch
Type: text/x-patch
Size: 2120 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190124/87015de9/attachment.bin>


More information about the llvm-commits mailing list