Compilation error with nvcc and c++11, need minimal failing example

百般思念 提交于 2019-12-11 05:48:28

问题


The following code (originally from Boost) fails to compile using nvcc 7.0 with C++11 support enabled:

#include <memory>

template<typename T>
struct result_of_always_void
{
    typedef void type;
};

template<typename F, typename Enable = void> struct cpp0x_result_of_impl {};

template<typename F,typename T0>
struct cpp0x_result_of_impl<F(T0), typename result_of_always_void< decltype(std::declval<F>()(std::declval<T0 >()))>::type >
{
    typedef decltype(std::declval<F>()(std::declval<T0 >())) type;
};


int main ()
{
    return 0;
}

The error I get is the following:

test.cu:16:93: error: invalid use of qualified-name ‘std::allocator_traits<_Alloc>::propagate_on_container_swap’
   typedef decltype(std::declval<F>()(std::declval<T0 >())) type;
                                                                                             ^

I suspect this is due to a bug in the nvcc compiler, but before I file a bug, I wanted to ask if it is possible to simplify the code further while still having it produce the error?


回答1:


The issue appears to be fixed in cuda 7.5RC. Please switch to the newer cuda version.

$ cat t877.cu
#include <memory>

template<typename T>
struct result_of_always_void
{
    typedef void type;
};

template<typename F, typename Enable = void> struct cpp0x_result_of_impl {};

template<typename F,typename T0>
struct cpp0x_result_of_impl<F(T0), typename result_of_always_void< decltype(std::declval<F>()(std::declval<T0 >()))>::type >
{
    typedef decltype(std::declval<F>()(std::declval<T0 >())) type;
};


int main ()
{
    return 0;
}
$ /usr/local/cuda-7.0/bin/nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2015 NVIDIA Corporation
Built on Mon_Feb_16_22:59:02_CST_2015
Cuda compilation tools, release 7.0, V7.0.27
$ /usr/local/cuda-7.0/bin/nvcc -std=c++11 t877.cu -o t877
t877.cu:14:93: error: invalid use of qualified-name âstd::allocator_traits<_Alloc>::propagate_on_container_swapâ
     typedef decltype(std::declval<F>()(std::declval<T0 >())) type;
                                                                                             ^
$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2015 NVIDIA Corporation
Built on Thu_May__7_00:35:41_CDT_2015
Cuda compilation tools, release 7.5, V7.5.6
$ nvcc -std=c++11 t877.cu -o t877
$

You're welcome to file a bug, of course.



来源:https://stackoverflow.com/questions/31969644/compilation-error-with-nvcc-and-c11-need-minimal-failing-example

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!