编译错误与nvcc和c + + 11,需要最小的失败的例子 [英] Compilation error with nvcc and c++11, need minimal failing example

查看:526
本文介绍了编译错误与nvcc和c + + 11,需要最小的失败的例子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码(最初来自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:错误:无效使用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编译器驱动程序
版权所有(c)2005-2015 NVIDIA公司
建于Mon_Feb_16_22:59:02_CST_2015
Cuda编译工具,版本7.0,V7.0.27
$ /usr/local/cuda-7.0/bin/nvcc -std = c ++ 11 t877.cu -o t877
t877.cu:14:93:错误:无效使用qualified-nameâstd:: allocator_traits< _Alloc> ::propagate_on_container_swapâ
typedef decltype(std :: declval< F& ()(std :: declval< T0>()))类型;
^
$ nvcc --version
nvcc:NVIDIA(R)Cuda编译器驱动程序
版权所有(c)2005-2015 NVIDIA Corporation
Built on Thu_May__7_00:35: 41_CDT_2015
Cuda编译工具,版本7.5,V7.5.6
$ nvcc -std = c ++ 11 t877.cu -o t877
$



当然欢迎提交错误。


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?

解决方案

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.

这篇关于编译错误与nvcc和c + + 11,需要最小的失败的例子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆