Should g++ 4.4.7 -std=gnu++0x compile the "for each" construct?

c++, c++11, foreach, g++

Solution

No, support was added in GCC 4.6, see http://gcc.gnu.org/gcc-4.6/changes.html#cplusplus and http://gcc.gnu.org/projects/cxx0x.html

I realize g++4.4.7 is old, but shouldn't it even recognize the new construct, given the compiler flag?

No, why should it? You're suggesting that someone modifies the C++ parser to understand a new feature, just to reject it. That would be a waste of time - if someone has the time to modify the parser why not just add support for the feature? Otherwise they've got to modify the code, add testcases (to test it doesn't support the feature) etc. etc. Code changes to recognise new syntax don't just happen magically.

Problem

I'm currently stuck with g++ 4.4.7, and I tried using it (with the -std=gnu++0x flag) to compile a c++ program that used the "foreach" construct: ``` 190: void 191: Block::get_record_types(D_RecordType_Vector& record_type_vector) const { 192: for ( D_Record_Map::value_type rt_v_i : _records) { 193: 194: record_type_vector.push_back(rt_v_i.first); 195: } 196: } ``` The first error makes me think it just didn't recognize the construct: ``` ./c/Block.cpp:192: error: expected initializer before ':' token ./c/Block.cpp:196: error: expected primary-expression before '}' token ./c/Block.cpp:196: error: expected ';' before '}' token ./c/Block.cpp:196: error: expected primary-expression before '}' token ./c/Block.cpp:196: error: expected ')' before '}' token ./c/Block.cpp:196: error: expected primary-expression before '}' token ./c/Block.cpp:196: error: expected ';' before '}' token ``` This compiled correctly on Apple clang-425. I realize g++4.4.7 is old, but shouldn't it even recognize the new construct, given the compiler flag?

Original source