Nested object construction parse errors
Loren J. Rittle
rittle@supra.rsch.comm.mot.com
Thu Apr 8 19:14:00 GMT 1999
The following code:
; cat m.C
class inner
{
int t;
int s;
public:
inner (int _t, int _s) : t (_t), s (_s) {}
};
class outer
{
inner t;
int s;
public:
outer (const inner& _t, int _s) : t (_t), s (_s) {}
};
int g (int r);
void
f (void)
{
outer a (inner (g (1), 2), 3); // line 22
}
When compiled under g++ (egcs-2.93.16 for sparc-sun-solaris2.6),
produces a fatal parse error:
; g++ -c -O2 m.C
m.C: In function `void f()':
m.C:22: parse error before `,'
The obvious workaround of assigning the result of g () to a new
temporary variable does seem to work. This related test case might
give someone additional ideas about where the problem lies:
; cat n.C
class inner
{
int t;
public:
inner (int _t) : t (_t) {}
};
class outer
{
inner t;
public:
outer (const inner& _t) : t (_t) {}
};
int g (int r, int s);
void
f (void)
{
outer a (inner (g (1, 2)));
// outer b (inner (g (1))); // this line compiles, but shouldn't have!
// bad code is generated; b is given a
// bizarre type thus causing code that uses
// b to fail to compile
}
; g++ -c -O2 n.C
n.C: In function `void f()':
n.C:20: no matching function for call to `inner::inner (int, int)'
n.C:5: candidates are: inner::inner(int)
n.C:6: inner::inner(const inner &)
Regards,
Loren
More information about the Gcc-bugs
mailing list