1

Does anyone know if libstdc++ in g++ <= 4.9 is fully C++11-compliant (or claimed to be)? For example, the code below does not compile (compiles on 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;
}

The overload of std::string::insert I'm using is declared in 21.4.6.4/21 (N3936) as returning an iterator to the first character inserted

iterator insert(const_iterator p, size_type n, charT c);

however in the code above it returns void. Is the std::string part of the library non-compliant? I wonder if it compiles on g++4.10.

vsoftco
  • 55,410
  • 12
  • 139
  • 252
  • 3
    No, `libstdc++` does not fully implement C++11 yet. For example, the entire `codecvt` header is missing. – Brian Bi Aug 07 '14 at 00:07
  • 1
    It's unlikely that the libstdc++ implementation of std::string will be fully c++11 compliant for a while. It would require a ABI incompatible change to the implementation. See: http://stackoverflow.com/questions/12199710/legality-of-cow-stdstring-implementation-in-c11 – Bill Lynch Aug 07 '14 at 00:12
  • 1
    See https://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html#status.iso.2011 – Praetorian Aug 07 '14 at 00:12
  • Ok, I see, thanks! @Praetorian thanks, saw that before but didn't realize that at the bottom there was another section dedicated for the STL. Is there any compiler as of now that have an STL that's fully standard-compliant? At least clang claims "libc++ is a 100% complete C++11 implementation on Apple's OS X." http://libcxx.llvm.org/ is it indeed so? – vsoftco Aug 07 '14 at 00:15
  • 2
    I'd believe libc++'s claim (maybe Howard will see this and corroborate that). FWIW, I think MSVC's stdlib implementation is complete to the extent allowed by the compiler. Unfortunately that compiler's so far behind that that's not saying much. – Praetorian Aug 07 '14 at 00:24
  • @vsoftco: I have just found a non-compliance in libc++ (actually, non-compliance with even C++98), so no. But it is the closest we have now. – Siyuan Ren Aug 07 '14 at 03:02
  • @C.R. what's the non-compliance? – vsoftco Aug 07 '14 at 03:04
  • 2
    N3936 is not (yet) a standard. It's a candidate draft for C++14. – Casey Aug 07 '14 at 03:15
  • 1
    @vsoftco: http://stackoverflow.com/questions/24475056/is-libcs-implementation-of-stdmake-heap-nonconformant It is a minor bug, but non-compliance indeed. – Siyuan Ren Aug 07 '14 at 03:21
  • @Casey yes I know, that was the reference I had on my computer (and that part of the string class didn't change), but know for sure the signature of the function I mentioned and that it has to return an iterator in std c++11. It used to return `void` before c++11. – vsoftco Aug 07 '14 at 03:40
  • I came upon this question looking for potential duplicates for a question I was going to post. I am surprised there are not more similar questions. – Shafik Yaghmour Mar 28 '15 at 22:45
  • @ShafikYaghmour I don't even remember now how I came up with this question, was during my C++11-learning period. Were you going to ask the same question? – vsoftco Mar 28 '15 at 22:46
  • Different but related question, I link to it in my answer, this one had to do with allocators. I kept the window open and just came back to it today. – Shafik Yaghmour Mar 28 '15 at 22:47
  • @ShafikYaghmour as far as I am aware, libc++ seems to be "closer" to the standard than libstdc++. g++5 seem to be a nice step forward though. The only thing that (at least for me) is a big minus for clang/llvm is the lack of OpenMP support (by default). You can get it to work, but it is a real pain, and I use OpenMP extensively, so I had to take the other route of using g++ on Mac, which is almost as painful... – vsoftco Mar 28 '15 at 22:50

1 Answers1

1

N3936 is a C++14 draft, for C++11 the closest draft standard would be N3337 but in this case it still has a return type of iterator so the issue is the same.

The link that Praetorian provides in his comment does not seem to have the information anymore and I can not find a specific bug report for this case but in a related case where libstdc++ and libc++ disagree: Does C++11 require allocators to be default constructible, libstdc++ and libc++ disagree? the issue is the same.

libstdc++ implementation of std::string is not fully C++11 compliant but in this bug report we can see that with gcc 5.0 release this should be fixed:

Fixed for GCC 5 (when using the new string ABI)

and we can see this live .

Community
  • 1
  • 1
Shafik Yaghmour
  • 154,301
  • 39
  • 440
  • 740