我試圖編譯C++庫(與海灣合作委員會5.3.1-14ubuntu2),並得到了這種類型的錯誤:明確違約功能不能被聲明爲constexpr因爲隱式聲明不constexpr
> 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」。這可能是相關的
我環顧四周,但到目前爲止找不到解決此問題的方法。 這裏有一些類似的問題,可以幫助:
constexpr defining static data member of literal type that is declared const constructor of derived class cannot be constexpr if base class contains array member
它[作品](http://coliru.stacked-crooked.com/a/c32bbd2a1633014f)與GCC 7.2.0以及鏗鏘3.8.0。 – Darklighter