r336026 - [CUDA] Make __host__/__device__ min/max overloads constexpr in C++14.

Justin Lebar via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 29 15:28:09 PDT 2018


Author: jlebar
Date: Fri Jun 29 15:28:09 2018
New Revision: 336026

URL: http://llvm.org/viewvc/llvm-project?rev=336026&view=rev
Log:
[CUDA] Make __host__/__device__ min/max overloads constexpr in C++14.

Summary: Tests in a separate change to the test-suite.

Reviewers: rsmith, tra

Subscribers: lahwaacz, sanjoy, cfe-commits

Differential Revision: https://reviews.llvm.org/D48151

Modified:
    cfe/trunk/lib/Headers/cuda_wrappers/algorithm

Modified: cfe/trunk/lib/Headers/cuda_wrappers/algorithm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/cuda_wrappers/algorithm?rev=336026&r1=336025&r2=336026&view=diff
==============================================================================
--- cfe/trunk/lib/Headers/cuda_wrappers/algorithm (original)
+++ cfe/trunk/lib/Headers/cuda_wrappers/algorithm Fri Jun 29 15:28:09 2018
@@ -67,34 +67,43 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #endif
 #endif
 
+#pragma push_macro("_CPP14_CONSTEXPR")
+#if __cplusplus >= 201402L
+#define _CPP14_CONSTEXPR constexpr
+#else
+#define _CPP14_CONSTEXPR
+#endif
+
 template <class __T, class __Cmp>
 __attribute__((enable_if(true, "")))
-inline __host__ __device__ const __T &
+inline _CPP14_CONSTEXPR __host__ __device__ const __T &
 max(const __T &__a, const __T &__b, __Cmp __cmp) {
   return __cmp(__a, __b) ? __b : __a;
 }
 
 template <class __T>
 __attribute__((enable_if(true, "")))
-inline __host__ __device__ const __T &
+inline _CPP14_CONSTEXPR __host__ __device__ const __T &
 max(const __T &__a, const __T &__b) {
   return __a < __b ? __b : __a;
 }
 
 template <class __T, class __Cmp>
 __attribute__((enable_if(true, "")))
-inline __host__ __device__ const __T &
+inline _CPP14_CONSTEXPR __host__ __device__ const __T &
 min(const __T &__a, const __T &__b, __Cmp __cmp) {
   return __cmp(__b, __a) ? __b : __a;
 }
 
 template <class __T>
 __attribute__((enable_if(true, "")))
-inline __host__ __device__ const __T &
+inline _CPP14_CONSTEXPR __host__ __device__ const __T &
 min(const __T &__a, const __T &__b) {
   return __a < __b ? __a : __b;
 }
 
+#pragma pop_macro("_CPP14_CONSTEXPR")
+
 #ifdef _LIBCPP_END_NAMESPACE_STD
 _LIBCPP_END_NAMESPACE_STD
 #else




More information about the cfe-commits mailing list