diff --git a/libcudacxx/include/cuda/std/__complex/literals.h b/libcudacxx/include/cuda/std/__complex/literals.h index d31b832c8d1..bc105f48a55 100644 --- a/libcudacxx/include/cuda/std/__complex/literals.h +++ b/libcudacxx/include/cuda/std/__complex/literals.h @@ -21,28 +21,28 @@ # pragma system_header #endif // no system header -#include +// gcc < 8 warns about it's extended literals being shadowed by the implementation, so let's just disable the complex +// literals +#if !_CCCL_COMPILER(GCC, <, 8) -#include +# include -_CCCL_BEGIN_NAMESPACE_CUDA_STD +# include -#ifdef _LIBCUDACXX_HAS_STL_LITERALS -// Literal suffix for complex number literals [complex.literals] +_CCCL_BEGIN_NAMESPACE_CUDA_STD _CCCL_DIAG_PUSH _CCCL_DIAG_SUPPRESS_GCC("-Wliteral-suffix") _CCCL_DIAG_SUPPRESS_CLANG("-Wuser-defined-literals") -_CCCL_DIAG_SUPPRESS_MSVC(4455) +_CCCL_DIAG_SUPPRESS_NVHPC(lit_suffix_no_underscore) +_CCCL_DIAG_SUPPRESS_MSVC(4455) // literal suffix identifiers that do not start with an underscore are reserved +_CCCL_BEGIN_NV_DIAG_SUPPRESS(2506, 20208) // a user-provided literal suffix must begin with "_", + // long double treated as double inline namespace literals { inline namespace complex_literals { -# if !_CCCL_CUDA_COMPILER(NVCC) && !_CCCL_COMPILER(NVRTC) -// NOTE: if you get a warning from GCC <7 here that "literal operator suffixes not preceded by ‘_’ are reserved for -// future standardization" then we are sorry. The warning was implemented before GCC 7, but can only be disabled since -// GCC 7. See also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69523 _CCCL_API constexpr complex operator""il(long double __im) { return {0.0l, __im}; @@ -71,36 +71,16 @@ _CCCL_API constexpr complex operator""if(unsigned long long __im) { return {0.0f, static_cast(__im)}; } -# else // ^^^ !_CCCL_CUDA_COMPILER(NVCC) && !_CCCL_COMPILER(NVRTC) ^^^ / vvv other compilers vvv -_CCCL_API constexpr complex operator""i(double __im) -{ - return {0.0, static_cast(__im)}; -} - -_CCCL_API constexpr complex operator""i(unsigned long long __im) -{ - return {0.0, static_cast(__im)}; -} - -_CCCL_API constexpr complex operator""if(double __im) -{ - return {0.0f, static_cast(__im)}; -} - -_CCCL_API constexpr complex operator""if(unsigned long long __im) -{ - return {0.0f, static_cast(__im)}; -} -# endif // other compilers } // namespace complex_literals } // namespace literals +_CCCL_END_NV_DIAG_SUPPRESS() _CCCL_DIAG_POP -#endif // _LIBCUDACXX_HAS_STL_LITERALS - _CCCL_END_NAMESPACE_CUDA_STD -#include +# include + +#endif // !_CCCL_COMPILER(GCC, <, 8) #endif // _CUDA_STD___COMPLEX_LITERALS_H diff --git a/libcudacxx/include/cuda/std/__internal/features.h b/libcudacxx/include/cuda/std/__internal/features.h index 4c2eb5cfd94..d038c012753 100644 --- a/libcudacxx/include/cuda/std/__internal/features.h +++ b/libcudacxx/include/cuda/std/__internal/features.h @@ -69,9 +69,4 @@ # define _LIBCUDACXX_HAS_NVBF16() 0 #endif // _CCCL_HAS_NVBF16() && _CCCL_CTK_AT_LEAST(12, 2) -// NVCC does not have a way of silencing non '_' prefixed UDLs -#if !_CCCL_CUDA_COMPILER(NVCC) && !_CCCL_COMPILER(NVRTC) -# define _LIBCUDACXX_HAS_STL_LITERALS -#endif // !_CCCL_CUDA_COMPILER(NVCC) && !_CCCL_COMPILER(NVRTC) - #endif // _CUDA_STD___INTERNAL_FEATURES_H diff --git a/libcudacxx/test/libcudacxx/std/numerics/complex.number/complex.literals/literals.pass.cpp b/libcudacxx/test/libcudacxx/std/numerics/complex.number/complex.literals/literals.pass.cpp new file mode 100644 index 00000000000..e6e542ac01e --- /dev/null +++ b/libcudacxx/test/libcudacxx/std/numerics/complex.number/complex.literals/literals.pass.cpp @@ -0,0 +1,64 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +// + +// UNSUPPORTED: gcc-7 + +#include +#include +#include + +#include "test_macros.h" + +__host__ __device__ constexpr bool test() +{ + using namespace cuda::std::literals::complex_literals; + + static_assert(cuda::std::is_same_v>); + static_assert(cuda::std::is_same_v>); + static_assert(cuda::std::is_same_v>); + static_assert(cuda::std::is_same_v>); +#if _CCCL_HAS_LONG_DOUBLE() + static_assert(cuda::std::is_same_v>); + static_assert(cuda::std::is_same_v>); +#endif // _CCCL_HAS_LONG_DOUBLE() + + { + cuda::std::complex c1 = 3.0if; + assert((c1 == cuda::std::complex{0.0f, 3.0f})); + auto c2 = 3if; + assert(c1 == c2); + } + + { + cuda::std::complex c1 = 3.0i; + assert((c1 == cuda::std::complex{0.0f, 3.0})); + auto c2 = 3i; + assert(c1 == c2); + } + +#if _CCCL_HAS_LONG_DOUBLE() + { + cuda::std::complex c1 = 3.0il; + assert((c1 == cuda::std::complex{0.0f, 3.0l})); + auto c2 = 3il; + assert(c1 == c2); + } +#endif // _CCCL_HAS_LONG_DOUBLE() + + return true; +} + +int main(int, char**) +{ + test(); + static_assert(test()); + return 0; +}