Skip to content

Commit bb86c71

Browse files
authored
remove the use of NV_IF_TARGET in char_traits<char>::length (NVIDIA#4406)
`char_traits<char>::length` must be `constexpr`, and on nvc++ `NV_IF_TARGET` is never `constexpr`.
1 parent 454eb23 commit bb86c71

File tree

1 file changed

+5
-5
lines changed
  • libcudacxx/include/cuda/std/detail/libcxx/include

1 file changed

+5
-5
lines changed

libcudacxx/include/cuda/std/detail/libcxx/include/__string

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,13 +265,13 @@ struct _CCCL_TYPE_VISIBILITY_DEFAULT char_traits<char>
265265
{
266266
}
267267
#endif
268-
#if defined(_CCCL_BUILTIN_STRLEN)
269-
NV_IF_ELSE_TARGET(NV_IS_DEVICE,
270-
(size_t __len = 0; for (; !eq(*__s, char(0)); ++__s)++ __len; return __len;),
271-
(return _CCCL_BUILTIN_STRLEN(__s);))
268+
// nvcc and clang-cuda do not support __builtin_strlen in device code. nvhpc does
269+
// though. this check relies on the fact that nvhpc does not define __CUDA_ARCH__.
270+
#if defined(_CCCL_BUILTIN_STRLEN) && !defined(__CUDA_ARCH__)
271+
return _CCCL_BUILTIN_STRLEN(__s);
272272
#else
273273
size_t __len = 0;
274-
for (; !eq(*__s, char(0)); ++__s)
274+
while (*__s++)
275275
{
276276
++__len;
277277
}

0 commit comments

Comments
 (0)