2016-09-14 37 views
4

我玩弄type_traits,我發現了這個奇怪的std::string屬性:std :: string nothrow move可分配或可比?

$ 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 

然而cppreference聲稱move assignment operatorcomparison operators標記noexcept

我做錯了什麼?這是一個錯誤?

+0

也許只是一個不好的實現。在GCC 6中看起來像[它有效](http://melpon.org/wandbox/permlink/L8ZGpMveSiBnNj7a)。 –

+0

可能是我版本中的libstdC++錯誤。我想知道使用什麼版本 –

回答

3

但cppreference聲稱移動賦值運算符和比較運算符標記爲noexcept

有關於這一個缺陷報告,因爲C++ 11表示,此舉的任務是noexcept,但是那是不可能的,一般滿足(因爲它可能需要重新分配,如果從一個字符串中移動不兼容的分配是不傳播)。請參閱DR 2063

該標準已修復,以便異常規範取決於分配器的屬性,但直到該新規則在GCC中實現爲止,我們沒有執行操作noexcept。我實現了GCC 6.1的固定規則(請參閱PR 58265),並將此更改反向移植到gcc-5分支,但從那時起,還沒有另一個GCC 5.x版本。無論何時發生,它將在5.5版本中得到修復。

相關問題