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/
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
_______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
