Why does order of defining hidden friend binary operator- vs operator==, and using int vs concepts matter to NVCC?
01:00 31 Mar 2026
I'm trying to create a pointer like type wrapper for CUDA device pointers, but ran into a problem I can't reproduce with other compilers in regular MSVC or GCC. Basically, depending on the order I define operator- which I define as a hidden friend like so:
[[nodiscard]]
friend TestPointerLike operator-(TestPointerLike lhs, std::integral auto n) noexcept {
// lhs -= n; removed for now for simplicity in example, since only testing compilation
return lhs;
}
Depending on if I define it before operator == with std::nullopt_t, or after, or if I use int, or std::integral auto for n and I make it a non-hidden friend and just define it outside the class definition it may or may not compile the == operator. Why is this the case?
The following is the minimal example (there are four tests, with the final one, TestPointerLike4, being the failing case).
(187): error: no operator "==" matches these operands
operand types are: TestPointerLike4 == std::nullptr_t
bool bool_test = f64_ptr == nullptr;
^
(187): note #3328-D: built-in operator==(, ) does not match because argument #1 does not match parameter
bool bool_test = f64_ptr == nullptr;
^
(187): note #3328-D: built-in operator==(, ) does not match because argument #1 does not match parameter
bool bool_test = f64_ptr == nullptr;
^
1 error detected in the compilation of "".
Compiler returned: 2
c++cudac++20c++-conceptsnvcc
Your Answer
lock_outline
You need to log in to submit an answer.
Privacy & Cookie Consent
We use cookies to ensure the best experience on our website. This includes analytics, personalization, and marketing purposes. Some cookies are essential for the website to function properly.
By clicking "Accept", you consent to our use of cookies. You can read more about how we use cookies and how you can change your preferences in our Privacy Policy.