From ec5078cf9c9b4f24626303560b4b01b4f73cf1a6 Mon Sep 17 00:00:00 2001 From: Eric Niebler Date: Fri, 13 Dec 2024 20:21:10 +0000 Subject: [PATCH] make the `_CCCL_REQUIRES_EXPR` macro more robust `_CCCL_REQUIRES_EXPR` needs a unique identifier. currently it uses `__LINE__` to make an identifier unique, but that can cause conflicts. this PR changes it to use `__COUNTER__` instead when available. --- libcudacxx/include/cuda/std/__cccl/preprocessor.h | 6 ++++++ libcudacxx/include/cuda/std/__concepts/concept_macros.h | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/libcudacxx/include/cuda/std/__cccl/preprocessor.h b/libcudacxx/include/cuda/std/__cccl/preprocessor.h index 00e8d067878..4ba80e7c9de 100644 --- a/libcudacxx/include/cuda/std/__cccl/preprocessor.h +++ b/libcudacxx/include/cuda/std/__cccl/preprocessor.h @@ -28,6 +28,12 @@ # define _CCCL_HAS_INCLUDE(_X) 0 #endif +#ifdef __COUNTER__ +# define _CCCL_COUNTER() __COUNTER__ +#else +# define _CCCL_COUNTER() __LINE__ +#endif + #define _CCCL_PP_EXPAND(...) __VA_ARGS__ #define _CCCL_PP_EAT(...) diff --git a/libcudacxx/include/cuda/std/__concepts/concept_macros.h b/libcudacxx/include/cuda/std/__concepts/concept_macros.h index 84a79dc91ca..0d9374c3085 100644 --- a/libcudacxx/include/cuda/std/__concepts/concept_macros.h +++ b/libcudacxx/include/cuda/std/__concepts/concept_macros.h @@ -244,12 +244,12 @@ namespace __cccl_unqualified_cuda_std = _CUDA_VSTD; // NOLINT(misc-unused-alias- # define _CCCL_REQUIRES_EXPR(_TY, ...) \ ::__cccl_requires_expr_impl< \ - struct _CCCL_PP_CAT(__cccl_requires_expr_detail_, __LINE__) _CCCL_REQUIRES_EXPR_EXPAND_TPARAMS \ + struct _CCCL_PP_CAT(__cccl_requires_expr_detail_, _CCCL_COUNTER()) _CCCL_REQUIRES_EXPR_EXPAND_TPARAMS \ _TY>::__cccl_is_satisfied(static_cast<::__cccl_tag*>(nullptr), \ static_cast(nullptr)); \ - struct _CCCL_PP_CAT(__cccl_requires_expr_detail_, __LINE__) \ + struct _CCCL_PP_CAT(__cccl_requires_expr_detail_, _CCCL_COUNTER()) \ { \ - using __cccl_self_t = _CCCL_PP_CAT(__cccl_requires_expr_detail_, __LINE__); \ + using __cccl_self_t = _CCCL_PP_CAT(__cccl_requires_expr_detail_, _CCCL_COUNTER()); \ template \ _LIBCUDACXX_HIDE_FROM_ABI static auto __cccl_well_formed(__VA_ARGS__) _CCCL_REQUIRES_EXPR_2