我试图为Linux主机和QNX目标编译一个交叉编译器。
从foundry27网站获得了5.1版本。
因此,现在我暂停通过刚刚编译的中间xgcc编译目标libstdc++。尝试编译libstdc++/src/c++11/conditional_variable.cc时出错错误消息为:
In file included from /home/kovtyukhrd/toolchain/builds/gcc_5_1_branch/linux-x86-o-ntox86/i486-pc-nto-qnx8.0.0/libstdc++-v3/include/condition_variable:39:0,
from ../../../../../libstdc++-v3/src/c++11/condition_variable.cc:25:
/home/kovtyukhrd/toolchain/builds/gcc_5_1_branch/linux-x86-o-ntox86/i486-pc-nto-qnx8.0.0/libstdc++-v3/include/mutex:126:5: error: explicitly defaulted function 'constexpr std::mutex::mutex()' cannot be declared as constexpr because the implicit declaration is not constexpr:
mutex() noexcept = default;
^
/home/kovtyukhrd/toolchain/builds/gcc_5_1_branch/linux-x86-o-ntox86/i486-pc-nto-qnx8.0.0/libstdc++-v3/include/mutex:118:9: error: use of deleted function 'constexpr std::__mutex_base::__mutex_base()'
class mutex : private __mutex_base
^
/home/kovtyukhrd/toolchain/builds/gcc_5_1_branch/linux-x86-o-ntox86/i486-pc-nto-qnx8.0.0/libstdc++-v3/include/mutex:65:15: note: 'constexpr std::__mutex_base::__mutex_base() noexcept' is implicitly deleted because its exception-specification does not match the implicit exception-specification 'noexcept (false)'
constexpr __mutex_base() noexcept = default;
^
现在我可以看到,编译器试图隐式删除__mute_base构造函数,然后当我们试图在继承类(mutex)中使用它时,编译失败。在这里,我们可以阅读带有显式异常规范的函数的隐式删除,这与隐式异常规范不兼容(在此处获得此链接)。
现在我们应该考虑__mute_base()的"隐式异常规范'noexcept(false)'"。如果它应该调用具有"noexcept(false)"规范的函数,则可以将其隐式指定为"noexcpt(false))"。但经过预处理器,我们有了这个代码:
...
typedef struct _sync { int __count; unsigned __owner; } sync_t;
...
typedef struct _sync pthread_mutex_t;
...
typedef pthread_mutex_t __gthread_mutex_t;
...
class __mutex_base
{
protected:
typedef __gthread_mutex_t __native_type;
__native_type _M_mutex = { 0x80000000, 0xffffffff };
constexpr __mutex_base() noexcept = default;
# 78 "/home/kovtyukhrd/toolchain/builds/gcc_5_1_branch/linux-x86-o-ntox86/i486-pc-nto-qnx8.0.0/libstdc++-v3/include/mutex" 3
__mutex_base(const __mutex_base&) = delete;
__mutex_base& operator=(const __mutex_base&) = delete;
};
现在,问题是:"为什么__mute_base()有隐式异常规范'noexcept(false)'?"
另一个问题是,在不修改源代码的情况下,我应该如何正确编译这个库?
这是GCC 5.1中的一个问题,GCC 5.2中已经修复了这个问题。问题是0x80000000
不是_sync
结构的int
成员的有效初始值设定项,因为它超出了int
的范围,因此类型为unsigned的值也是如此。将其转换为int需要进行窄化转换,而常量表达式中不允许这样做。这使得构造函数变得非常常量(提到noexcept(false)
似乎是在转移注意力)。