Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 785
Chap Avatar asked Mar 10 '26 17:03

Chap


2 Answers

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.

like image 81
Jonathan Wakely Avatar answered Mar 12 '26 08:03

Jonathan Wakely


GCC 4.4.0 was released April 23, 2009. The wording for range-based for loops was finalized July 16, 2009. I'm not aware of any compiler writers with precognitive abilities.

like image 22
Casey Avatar answered Mar 12 '26 07:03

Casey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!