[PATCH] [libcxx] Use __decltype instead of __typeof__

Eric Fiselier eric at efcs.ca
Fri Jun 12 19:38:01 PDT 2015


Hi mclow.lists,

Both clang and GCC provide C++11 decltype semantics as __decltype in c++03 mode. We should use this instead of __typeof__ when availble. 

GCC added __decltype in 4.6.0, and AFAIK clang provided __decltype ever since 3.3. Unfortunately `__has_builtin(__decltype)` doesn't work for clang so we need to check the compiler version instead.

http://reviews.llvm.org/D10426

Files:
  include/__config

Index: include/__config
===================================================================
--- include/__config
+++ include/__config
@@ -21,6 +21,12 @@
 #define _GNUC_VER 0
 #endif
 
+#ifdef __clang__
+#define _CLANG_VER (__clang_major__ * 100 + __clang_minor__)
+#else
+#define _CLANG_VER 0
+#endif
+
 #if !_WIN32
 #include <unistd.h>
 #endif
@@ -577,7 +583,11 @@
 #endif  // _LIBCPP_HAS_NO_STATIC_ASSERT
 
 #ifdef _LIBCPP_HAS_NO_DECLTYPE
-#define decltype(x) __typeof__(x)
+# if _CLANG_VER >= 304 || _GNUC_VER >= 406
+#   define decltype(__x) __decltype(__x)
+# else
+#   define decltype(__x) __typeof__(__x)
+# endif
 #endif
 
 #ifdef _LIBCPP_HAS_NO_CONSTEXPR

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D10426.27624.patch
Type: text/x-patch
Size: 664 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150613/f6d90005/attachment.bin>


More information about the cfe-commits mailing list