有谁知道libstdc++
在g++ <= 4.9
完全符合 C++11(或声称符合)?例如,下面的代码不编译(在 clang 上编译):
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s;
// g++4.9 bug, returns void
// instead, according to the standard N3936 21.4.6.4/21
// should return an iterator (string::iterator or wrapper)
auto x = s.insert(s.begin(), 10,'A');
cout << s << endl;
}
std::string::insert
的过载我使用的是在 21.4.6.4/21 (N3936) 中声明为将迭代器返回到插入的第一个字符
iterator insert(const_iterator p, size_type n, charT c);
但是在上面的代码中它返回 void
.是 std::string
部分图书馆不合规?我想知道它是否可以在 g++4.10 上编译。
最佳答案
N3936
是 C++14 草案,对于 C++11,最接近的草案标准是 N3337但在这种情况下,它仍然有 iterator
的返回类型,所以问题是一样的。
Praetorian 在他的评论中提供的链接似乎不再包含该信息,我找不到针对此案例的特定错误报告,但在相关案例中 libstdc++
和 libc++
不同意:Does C++11 require allocators to be default constructible, libstdc++ and libc++ disagree?问题是一样的。
libstdc++
std::string
的实现不完全符合 C++11,但在此 bug report 中我们可以看到,随着 gcc 5.0
版本的发布,这个问题应该得到了修复:
Fixed for GCC 5 (when using the new string ABI)
我们可以 see this live .
关于c++ - g++4.9 libstdc++ std::string 对 C++11 的支持中断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25172211/