[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:26:10 PST 2019
haozhun created this revision.
haozhun added a reviewer: chandlerc.
Herald added subscribers: llvm-commits, kristina.
Visual Studio introduced __has_cpp_attributed in 15.8. However, Visual
Studio IntelliSense does not allow `::` in `__has_cpp_attributed`, and
produces error "E2512 the argument to a feature-test macro must be a
simple identifier" for code like `#if __has_cpp_attribute(clang::...)`.
The VS compiler does not produce this error. The error is only produced
by VS IntelliSense. As a result, without this commit, although the code
produces an error in Visual Studio development environment, it does not
make the actual build fail.
Repository:
rL LLVM
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
@@ -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.183410.patch
Type: text/x-patch
Size: 1716 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190124/27ed1861/attachment.bin>
More information about the llvm-commits
mailing list