小编Hen*_*rre的帖子

CUDA:在 constexpr if 函数中“在非空函数结束时缺少 return 语句”

当我编译以下测试代码时,我收到此警告:

test.cu(49): warning: missing return statement at end of non-void function "AllocateSize<T,D>(size_t) noexcept [with T=int, D=Device::GPU]"
          detected during instantiation of "Pointer<T, D> AllocateSize<T,D>(size_t) noexcept [with T=int, D=Device::GPU]" 
(61): here
Run Code Online (Sandbox Code Playgroud)

我应该担心吗,这是预期的吗?我该怎么做才能让它消失?这看起来很奇怪,因为 cuda 确实支持 C++17。提前致谢!

编译: nvcc -std=c++17 test.cu -o test

测试代码(test.cu):

enum class Device { CPU, GPU }; // Device

template <typename T, Device D>
class Pointer {
private:
    T* m_raw = nullptr;
    
public:
    __host__ __device__ inline Pointer(T* const p)              noexcept { this->SetPointer(p); }

    __host__ __device__ inline void SetPointer(const …
Run Code Online (Sandbox Code Playgroud)

c++ cuda

3
推荐指数
2
解决办法
239
查看次数

标签 统计

c++ ×1

cuda ×1