Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 14 additions & 34 deletions libcudacxx/include/cuda/std/__complex/literals.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,28 @@
# pragma system_header
#endif // no system header

#include <cuda/std/__complex/complex.h>
// 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)
Comment on lines +24 to +26
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to disable the literals for gcc 7 and older..


#include <cuda/std/__cccl/prologue.h>
# include <cuda/std/__complex/complex.h>

_CCCL_BEGIN_NAMESPACE_CUDA_STD
# include <cuda/std/__cccl/prologue.h>

#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<long double> operator""il(long double __im)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my understanding is that we don't support GCC <7, we can get rid of

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah

{
return {0.0l, __im};
Expand Down Expand Up @@ -71,36 +71,16 @@ _CCCL_API constexpr complex<float> operator""if(unsigned long long __im)
{
return {0.0f, static_cast<float>(__im)};
}
# else // ^^^ !_CCCL_CUDA_COMPILER(NVCC) && !_CCCL_COMPILER(NVRTC) ^^^ / vvv other compilers vvv
_CCCL_API constexpr complex<double> operator""i(double __im)
{
return {0.0, static_cast<double>(__im)};
}

_CCCL_API constexpr complex<double> operator""i(unsigned long long __im)
{
return {0.0, static_cast<double>(__im)};
}

_CCCL_API constexpr complex<float> operator""if(double __im)
{
return {0.0f, static_cast<float>(__im)};
}

_CCCL_API constexpr complex<float> operator""if(unsigned long long __im)
{
return {0.0f, static_cast<float>(__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 <cuda/std/__cccl/epilogue.h>
# include <cuda/std/__cccl/epilogue.h>

#endif // !_CCCL_COMPILER(GCC, <, 8)

#endif // _CUDA_STD___COMPLEX_LITERALS_H
5 changes: 0 additions & 5 deletions libcudacxx/include/cuda/std/__internal/features.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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.
//
//===----------------------------------------------------------------------===//

// <cuda/std/complex>

// UNSUPPORTED: gcc-7

#include <cuda/std/cassert>
#include <cuda/std/complex>
#include <cuda/std/type_traits>

#include "test_macros.h"

__host__ __device__ constexpr bool test()
{
using namespace cuda::std::literals::complex_literals;

static_assert(cuda::std::is_same_v<decltype(3.0if), cuda::std::complex<float>>);
static_assert(cuda::std::is_same_v<decltype(3if), cuda::std::complex<float>>);
static_assert(cuda::std::is_same_v<decltype(3.0i), cuda::std::complex<double>>);
static_assert(cuda::std::is_same_v<decltype(3i), cuda::std::complex<double>>);
#if _CCCL_HAS_LONG_DOUBLE()
static_assert(cuda::std::is_same_v<decltype(3.0il), cuda::std::complex<long double>>);
static_assert(cuda::std::is_same_v<decltype(3il), cuda::std::complex<long double>>);
#endif // _CCCL_HAS_LONG_DOUBLE()

{
cuda::std::complex<float> c1 = 3.0if;
assert((c1 == cuda::std::complex<float>{0.0f, 3.0f}));
auto c2 = 3if;
assert(c1 == c2);
}

{
cuda::std::complex<double> c1 = 3.0i;
assert((c1 == cuda::std::complex<double>{0.0f, 3.0}));
auto c2 = 3i;
assert(c1 == c2);
}

#if _CCCL_HAS_LONG_DOUBLE()
{
cuda::std::complex<long double> c1 = 3.0il;
assert((c1 == cuda::std::complex<long double>{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;
}