[Bug c++/12063] New: Enclosing temporary object constructors in parenthesis confuses compiler
tal_arie at yahoo dot com
gcc-bugzilla@gcc.gnu.org
Tue Aug 26 11:25:00 GMT 2003
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12063
Summary: Enclosing temporary object constructors in parenthesis
confuses compiler
Product: gcc
Version: 3.3
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: tal_arie at yahoo dot com
CC: gcc-bugs at gcc dot gnu dot org
There seems to be a problem compiling calls to constructors of temporary objects, when these
constructors are surrounded by parenthesis, as the test case below shows:
----- t.C
class A {
public:
A& operator=(const A& _a) { return *this; }
};
class B {
A& _a ;
public:
B(const A& a) : _a((A&)a) {}
} ;
void foo(const B& b) {
}
void bar() {
foo( B(A()) ) ; // this works
foo( B((A()) ) ; / this does not compile
A a;
foo( B( (a=A())) ) ; // this compiles
}
-------
Compiling:
g++ -c t.C
Result:
t.C: In function `void bar()':
t.C:17: error: parse error before `)' token
t.C:19: error: `a' undeclared (first use this function)
t.C:19: error: (Each undeclared identifier is reported only once for each
function it appears in.)
If I comment out line 17 (where the comments say it does not compile) I get a clean compile.
----------
As for the need to surround constructors with parenthesis, I'm creating objects using overloaded
operators, and use parenthesis to override the default operator precedence, only that with g++ it
does not seem to work (it does work with another compiler that I have tried).
More information about the Gcc-bugs
mailing list