我正在尝试编译以下代码:
#include <boost/optional.hpp>
void foo(boost::optional<unsigned> x = boost::none);
使用以下命令行放置在文件a.cu
中,使用 CUDA 编译器:
nvcc a.cu -c --std=c++11 -I/opt/boost/include
但我得到了一堆错误:
a.cu:2:53: error: conversion from ‘const boost::none_t(boost::none_t::init_tag (*)())’ to ‘boost::optional<unsigned int>’ is ambiguous
void foo(boost::optional<unsigned> x = boost::none);
^
/opt/boost/include/boost/optional/optional.hpp:805:1: note: candidate: boost::optional<T>::optional(boost::optional<T>::rval_reference_type) [with T = unsigned int; boost::optional<T>::rval_reference_type = unsigned int&&] <near match>
optional ( rval_reference_type val ) : base( boost::forward<T>(val) )
^ ~~~~
/opt/boost/include/boost/optional/optional.hpp:805:1: note: conversion of argument 1 would be ill-formed:
a.cu:2:53: error: invalid conversion from ‘const boost::none_t (*)(boost::none_t::init_tag (*)())’ to ‘unsigned int’ [-fpermissive]
void foo(boost::optional<unsigned> x = boost::none);
^
/opt/boost/include/boost/optional/optional.hpp:800:1: note: candidate: boost::optional<T>::optional(boost::optional<T>::argument_type) [with T = unsigned int; boost::optional<T>::argument_type = const unsigned int&] <near match>
optional ( argument_type val ) : base(val) {}
^ ~~~~
/opt/boost/include/boost/optional/optional.hpp:800:1: note: conversion of argument 1 would be ill-formed:
a.cu:2:53: error: invalid conversion from ‘const boost::none_t (*)(boost::none_t::init_tag (*)())’ to ‘unsigned int’ [-fpermissive]
void foo(boost::optional<unsigned> x = boost::none);
为什么会发生这种情况,我可以在使用 nvcc 编译的(主机端)代码中实际使用 boost::optional 的同时规避这个问题吗?
附加信息:
- 该代码使用 g++ 6.3.0(我的发行版的编译器)编译得很好。
- 这段代码(或者更确切地说,类似的代码)用于在我使用的早期 Linux 发行版上编译和工作,其中编译器是 g++ 5.4.x 。
- 我已经用 Boost 版本 1.65.1 和 1.69.0 试过这个。
- 我已经尝试过使用 CUDA 版本 9.2.88 和 10.0.130 。