c++/339: Parse error on constructor call
matt_conway@i2.com
matt_conway@i2.com
Tue Jun 20 14:56:00 GMT 2000
>Number: 339
>Category: c++
>Synopsis: Parse error on constructor call
>Confidential: no
>Severity: serious
>Priority: high
>Responsible: unassigned
>State: open
>Class: rejects-legal
>Submitter-Id: net
>Arrival-Date: Tue Jun 20 14:56:00 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator: matt_conway@i2.com
>Release: gcc/g++ snapshot 20000612
>Organization:
>Environment:
i686-pc-linux
>Description:
G++ has problems parsing a call to a constructor when the arguments for the ctor are produced by a chain of other method calls. See the code in the How-To-Repeat section for an example.
>How-To-Repeat:
Compile the following code with "g++ -g -c":
class Bar
{
public:
Bar& baz() {return *this;}
Bar& baz2() {return *this;}
void bar();
void bar2(const Bar& b) {}
};
class Foo
{
public:
Foo(const Bar& b) {}
void foo() {}
};
void Bar::bar()
{
bar2(baz().baz2());
Foo foovar(baz().baz2());
// These three give a parse error
Foo(baz().baz2()).foo();
Foo(baz()).foo();
Foo(baz().baz2());
// This one works
Foo(baz());
}
>Fix:
Have an intermediary reference variable, e.g:
Bar&b = baz().baz2();
Foo(b).foo();
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the Gcc-prs
mailing list