我正在尝试编译一个C++库(使用gcc 5.3.1-14ubuntu2),并得到了这种类型的错误:
> In file included from
> /root/pitchfork/workspace/unanimity/include/pacbio/consensus/ModelConfig.h:49:0,
> from /root/pitchfork/workspace/unanimity/src/models/P6C4NoCovModel.cpp:42:
> /root/pitchfork/workspace/unanimity/include/pacbio/data/internal/BaseEncoding.h:119:31:
> error: explicitly defaulted function 'constexpr
> PacBio::Data::detail::NCBI2na&
> PacBio::Data::detail::NCBI2na::operator=(const
> PacBio::Data::detail::NCBI2na&)' cannot be declared as constexpr
> because the implicit declaration is not constexpr:
> inline constexpr NCBI2na& operator=(const NCBI2na&) = default;
代码中引起麻烦的部分是:
class NCBI2na
{
public:
static inline constexpr NCBI2na FromASCII(const char base) { return NCBI2na{base}; }
static inline constexpr NCBI2na FromRaw(const uint8_t raw) { return NCBI2na{raw}; }
public:
~NCBI2na() = default;
inline constexpr NCBI2na(const NCBI2na&) = default;
inline constexpr NCBI2na(NCBI2na&&) = default;
inline constexpr NCBI2na& operator=(const NCBI2na&) = default;
inline constexpr NCBI2na& operator=(NCBI2na&&) = default;
};
代码中似乎会引起麻烦的部分是"= default“。这也可能是相关的
我环顾四周,到目前为止还没有找到解决这个问题的办法。以下是一些类似的问题,可能会有所帮助:
发布于 2017-10-15 16:18:47
这好像是GCC的窃听器。假设编译为C++14,那么编写的规则如下:
常设委员会职能的定义应满足下列限制:
实际上,上述所有内容都满足于您向我们展示的代码。因此,您的赋值运算符定义是可以的,并且应该被接受为constexpr
。
这段代码(一旦错误导致的静态函数被注释掉)将被GCC 5.4.0接受。所以你绝对可以把它归因于编译器的错误。
https://stackoverflow.com/questions/46756288
复制相似问题