PDA

View Full Version : g++ 4.2 strange compile errors



benguin
April 17th, 2008, 06:52 PM
Hello,
I use (and maintain and write code for) a robot control software, writen entirely in C++. The code used to compile fine with g++4.1, under Gutsy Gibbon. I recently dist-upgraded too Hardy, and it switched to using g++4.2 as the default compiler. With that started zillions of error messages, all seem to be originating from the C++ standard headers. Here's an example:


In file included from /usr/include/c++/4.2/bits/char_traits.h:46,
from /usr/include/c++/4.2/ios:45,
from /usr/include/c++/4.2/ostream:45,
from /usr/include/c++/4.2/iostream:45,
from /home/junaed/work/C++/RoboDevel/RHex/include/behaviors/NMTune.hh:55,
from /home/junaed/work/C++/RoboDevel/RHex/include/behaviors/TuneMode.hh:66,
from supervisor.cc:26:

and one more:


/usr/include/c++/4.2/bits/stl_algobase.h: At global scope:
/usr/include/c++/4.2/bits/stl_algobase.h:182: error: expected unqualified-id before ‘const’
/usr/include/c++/4.2/bits/stl_algobase.h:182: error: expected `)' before ‘const’
/usr/include/c++/4.2/bits/stl_algobase.h:182: error: expected `)' before ‘const’
/usr/include/c++/4.2/bits/stl_algobase.h:182: error: expected initializer before ‘const’
/usr/include/c++/4.2/bits/stl_algobase.h:204: error: expected unqualified-id before ‘const’
/usr/include/c++/4.2/bits/stl_algobase.h:204: error: expected `)' before ‘const’
/usr/include/c++/4.2/bits/stl_algobase.h:204: error: expected `)' before ‘const’
/usr/include/c++/4.2/bits/stl_algobase.h:204: error: expected initializer before ‘const’


The source supervisor.cc at line 26 has this:


#include <iostream>

I did some google searches, but came up with zip. Did I bork something during the dist-upgrade? Any ideas/suggestions would be really helpful! It seems really weird that including <iostream> would result in something so catastrophic!!

Regards,
-J-

Wybiral
April 17th, 2008, 07:18 PM
Can you post the code? If just using "#include <iostream>" doesn't reproduce the error, then it might be in the code before it (maybe a missing semicolon or something).

benguin
April 17th, 2008, 08:29 PM
Hi,
The code is quite large complex to post, but I investigated a bit more, and traced this error I was getting:


In file included from /usr/include/c++/4.2/bits/char_traits.h:46,
from /usr/include/c++/4.2/ios:45,
from /usr/include/c++/4.2/ostream:45,
from /usr/include/c++/4.2/iostream:45,
from /home/junaed/work/C++/RoboDevel/RHex/include/behaviors/NMTune.hh:55,
from /home/junaed/work/C++/RoboDevel/RHex/include/behaviors/TuneMode.hh:66,
from supervisor.cc:26:
/usr/include/c++/4.2/bits/stl_algobase.h:226:56: error: macro "min" passed 3 arguments, but takes just 2

The same error does not show up if I'm using g++ 4.1. The files, at least those sections in /usr/include/c++/4.2/bits/stl_algobase.h are identical. The compile command looks like this: (I removed the project-specific include and library paths for clarity)


g++ -fno-rtti -Wall -g -D_LINUX_ -c -o supervisor.o supervisor.cc


The _D_LINUX_ flag is used as the code is also built under the QNX RTOS.

Thanks.

-J-

dstud395
May 7th, 2008, 11:11 PM
I just had this error and fixed it. For me, I didn't close a class with }; For instance, I did something like this:



class Foo {
public:
Foo(int);
print(string);
private:
int member;



I didn't end the class definition. See if this helps.