Is GCC 4.8.1 C++11 complete?

倾然丶 夕夏残阳落幕 提交于 2020-02-03 06:35:32

问题


OS is windows.

I'll start off by saying that I have no experience with C++, or any other compiled language. I've used CPython a bit and am familiar with that, but, until earlier today, I'd never even glanced at C++ source.

I'm trying to teach myself C++, so I've been playing around with it a bit, and one problem I'm having is the error:

error: 'to_string' was not declared in this scope

Apparently, to_string is a C++11 thing, which should be fine. I downloaded the latest MinGW, added it to my path - I have checked, and running

g++ - v

does indeed tell me that I have version 4.8.1 installed. The IDE I'm working with, Code::Blocks finds it no problem, but it simply won't use any of the C++11 stuff, giving me errors such as the one above. Things not exclusive to C++11 compile fine.

There is a section under compiler flags to "follow the C++11 language standard", which I have checked, but, even then, I get the same errors. I'm really not sure what's going on - I've looked this up, and all of the suggestions are to update either the IDE or MinGW (both of which are up to date), or to select that flag, which, as I said, is already selected.

Does anyone with more experience with C++ have any idea what might be going on?b


回答1:


My understanding is that, other than regex support, G++'s C++11 support is largely complete with 4.8.1.

The following two links highlight the status of C++11 support in G++ 4.8.1 and libstdc++:

  • C++11 status in GCC 4.8.x.
  • C++11 status in libstdc++. Note that this is for the latest SVN release, not tied to a specific G++ release; therefore expect it to be "optimistic" with respect to G++.

To compile C++11 code, though, you need to include the command line flag -std=c++11 when you compile.




回答2:


std::string is not compliant; it still uses legacy (and buggy especially with threads) 'copy on write' behavior. You might be able to use __gnu_cxx::__vstring as a workaround.

"Class template basic_string Partial Non-conforming Copy-On-Write implementation"

http://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html#status.iso.200x https://gcc.gnu.org/bugzilla/show_bug.cgi?id=21334

Related: Does g++ meets std::string C++11 requirements




回答3:


The g++ 4.8 series was not complete with regard to the core language. The following compiles and runs with g++ 4.9 and higher (and also with clang++ 3.3 and higher), but not with g++ 4.8.5 (or with any previous member of the g++ 4.8 series).

#include <iostream>

void ordinary_function (int&)  { std::cout << "ordinary_function(int&)\n"; }   

void ordinary_function (int&&) { std::cout << "ordinary_function(int&&)\n"; }   

template<class T>
void template_function (T&)  { std::cout << "template_function(T&)\n"; }   

template<class T>
void template_function (T&&) { std::cout << "template_function(T&&)\n"; }   

int main () {   
    int i = 42; 
    ordinary_function(42); // Not ambiguous.
    ordinary_function(i);  // Not ambiguous.
    template_function(42); // Not ambiguous.
    template_function(i);  // Ambiguous in g++4.8.
}   


来源:https://stackoverflow.com/questions/20534679/is-gcc-4-8-1-c11-complete

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!