std::string not nothrow move 可分配或可比较?

小太郎*_*小太郎 5 c++ type-traits

我在玩弄type_traits,我发现了这个奇怪的属性std::string

$ cat a.cpp
#include <string>
#include <type_traits>

static_assert(std::is_nothrow_move_assignable<std::string>::value, "???");
static_assert(noexcept(std::declval<std::string>() == std::declval<std::string>()), "???");
$ g++ -std=c++14 a.cpp
a.cpp:4:1: error: static assertion failed: ???
 static_assert(std::is_nothrow_move_assignable<std::string>::value, "???");
 ^
a.cpp:5:1: error: static assertion failed: ???
 static_assert(noexcept(std::declval<std::string>() == std::declval<std::string>()), "???");
 ^
$ g++ --version
g++ (Ubuntu 5.4.0-6ubuntu1~16.04.2) 5.4.0 20160609
Run Code Online (Sandbox Code Playgroud)

然而 cppreference 声称移动赋值运算符比较运算符被标记为noexcept

难道我做错了什么?这是一个错误吗?

Jon*_*ely 4

然而 cppreference 声称移动赋值运算符和比较运算符已被标记noexcept

有一个关于此的缺陷报告,因为 C++11 表示移动分配是,noexcept但一般来说这是不可能满足的(因为如果从具有不传播的不兼容分配器的字符串移动,则可能需要重新分配)。参见DR 2063

该标准已被修复,因此异常规范取决于分配器的属性,但在 GCC 中实现新规则之前,我们没有进行操作noexcept。我实现了 GCC 6.1 的固定规则(请参阅PR 58265)并将更改反向移植到 gcc-5 分支,但从那时起就没有再发布 GCC 5.x 了。无论何时发生这种情况,它都会在 5.5 版本中修复。