nvcc 和 c++11 的编译错误,需要最少的失败示例
Compilation error with nvcc and c++11, need minimal failing example
以下代码(最初来自 Boost)无法使用启用了 C++11 支持的 nvcc 7.0 进行编译:
#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;
}
我得到的错误如下:
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;
^
我怀疑这是由于 nvcc 编译器中的一个错误,但在我提交错误之前,我想问一下是否可以进一步简化代码,同时仍然产生错误?
该问题似乎已在 cuda 7.5RC 中得到修复。请切换到较新的cuda版本。
$ 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
$
当然欢迎您提交错误。
以下代码(最初来自 Boost)无法使用启用了 C++11 支持的 nvcc 7.0 进行编译:
#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;
}
我得到的错误如下:
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;
^
我怀疑这是由于 nvcc 编译器中的一个错误,但在我提交错误之前,我想问一下是否可以进一步简化代码,同时仍然产生错误?
该问题似乎已在 cuda 7.5RC 中得到修复。请切换到较新的cuda版本。
$ 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
$
当然欢迎您提交错误。