libstdc++ QNX 交叉编译在 mutex class 编译时失败

libstdc++ QNX cross-compilation fails on mutex class compilation

我尝试为 Linux-host 和 QNX-target 编译一个交叉编译器。

从 foundry27 站点获得 5.1 版本。

所以现在我在编译目标 libstdc++ 的中间 xgcc 编译上停滞不前。尝试编译 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;
           ^

所以现在我可以看到,编译器试图隐式删除 __mutex_base 构造函数,然后当我们尝试在继承的 class(互斥锁)中使用它时编译失败。 Here we can read about implicit deletion of functions with explicit exception-specification, that is not compatible with implicit exception-specification (got this link ).

现在我们应该考虑__mutex_base()的"implicit exception-specification 'noexcept (false)'"。如果要调用具有 'noexcept (false)' 规范的函数,则可以将其隐式指定为 'noexcept (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;
  };

现在 -- 问题:"Why the __mutex_base() has the implicit exception-specification 'noexcept (false)'?"

另一个问题是我应该如何在不修改源代码的情况下正确编译这个库?

这是 GCC 5.1 中的问题,已在 GCC 5.2 中修复。问题是 0x80000000 不是 _sync 结构的 int 成员的有效初始值设定项,因为它超出了 int 的范围,所以是 int 的值输入无符号。将其转换为 int 需要收缩转换,这在常量表达式中是不允许的。这使得构造函数成为非 constexpr(提到 noexcept(false) 似乎是在转移注意力)。