This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
CVS head (gcc-3.4), problem with new parser?
- From: Andrew Pollard <andrewp at andypo dot net>
- To: gcc at gcc dot gnu dot org
- Date: Tue, 31 Dec 2002 10:54:40 GMT
- Subject: CVS head (gcc-3.4), problem with new parser?
Hi All,
I've been trying out the new C++ parser on some of our source code
and it threw up a problem that I'm not sure is standard mandated or
not...
Should the following code compile?
a.cxx:
-------------------------
struct A {
int a, b;
A(int i, int j) : a(i), b(j) {}
void foo() {};
};
int
main()
{
int a = 2;
A(a, a).foo();
return (0);
}
--------------------------
% g++34 -v
Reading specs from /usr/local/gcc-3.4-20021231-i686-pc-linux-gnu/lib/gcc-lib/i686-pc-linux-gnu/3.4/specs
Configured with:
Thread model: posix
gcc version 3.4 20021230 (experimental)
% g++34 a.cxx
a.cxx: In function `int main()':
a.cxx:11: error: conflicting types for `A a'
a.cxx:10: error: previous declaration as `int a'
a.cxx:11: error: expected init-declarator
a.cxx:11: error: expected `,' or `;'
It appears to think that I want to declare a new variable 'a' with
type 'A', whereas I want to construct a temporary A(2,2) and invoke
foo() on it. [*]
Previous versions of g++ work (3.0-cvs, 3.2-cvs, 3.3-cvs) and so do
icc70 and VC++6.0
[ (*)
As an aside, I didn't realise until investigating this that things like
int(a);
actually declare variables.... thus with the following struct
struct A {
int a;
A(int _a = 0) : a(_a) {}
};
Then
A(a);
declares a variable called 'a' of type 'A' with value 0 (assuming that
there is no 'a' in scope)
A(a);
causes a 'redefinition' or 'shadowing' error if there is an 'a' in scope, and
A(1);
creates and destroys a temporary variable of type 'A' with value 1
which is all rather confusing... Is this what the standard indicates?
In the case that I provided, I think the parser is getting confused
since there are two arguments to A(a, a), so this can never be thought
of as declaring a new variable of type A, it must be a temporary, but
the parser isn't noticing this....
]
Comments?
Andrew.
--
Andrew Pollard, Brooks-PRI Automation | home: andrew@andypo.net
670 Eskdale Road, Winnersh Triangle, UK | work: Andrew.Pollard@brooks-pri.com
Tel/Fax:+44 (0)118 9215603 / 9215660 | http://www.andypo.net