views:

56

answers:

2

Hi everybody!

I have a strange problem with my code when porting from a computer with glibc-2.5-25 (suse 10.2) to a computer with glibc-2.3.2-6 (suse 8.2). I use several method calls on temporary objects and they are not working on the older machine.

class A
{
public:
    A(int n) {}
    void method() {}
};

int main()
{
    A(10).method(); //here the compiler gives parse error before . 

    A a(10);
    a.method(); //this works fine 
}

Could this really happen because of the older libc version or it might be a setting in my IDE (compiler setting)?

+1  A: 

Why would the libc version influence a parse error? g++ version would be more useful.

gcc changed its parser around version 3.4 and solved at the time a lot of parsing issues which weren't easy to fix in the old yacc parser. That could explain what you see.

AProgrammer
A: 

This seems to be a compiler bug: http://gcc.gnu.org/ml/gcc-bugs/1998-10/msg00178.html (older version, same bug). A workaround with identical semantics would be something like:

#define TEMP(T, x, y) { T _temporary(x); _temporary.y; }

A(10).method(); // is:
TEMP(A, 10, method())

Yuck.

GMan