public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* CVS head (gcc-3.4), problem with new parser?
@ 2002-12-31  3:42 Andrew Pollard
  2002-12-31  3:47 ` Gabriel Dos Reis
  2002-12-31  9:17 ` Alexandre Oliva
  0 siblings, 2 replies; 5+ messages in thread
From: Andrew Pollard @ 2002-12-31  3:42 UTC (permalink / raw)
  To: gcc


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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: CVS head (gcc-3.4), problem with new parser?
  2002-12-31  3:42 CVS head (gcc-3.4), problem with new parser? Andrew Pollard
@ 2002-12-31  3:47 ` Gabriel Dos Reis
  2002-12-31  6:36   ` Andrew Pollard
  2002-12-31  8:22   ` Andrew Pollard
  2002-12-31  9:17 ` Alexandre Oliva
  1 sibling, 2 replies; 5+ messages in thread
From: Gabriel Dos Reis @ 2002-12-31  3:47 UTC (permalink / raw)
  To: Andrew Pollard; +Cc: gcc

Andrew Pollard <andrewp@andypo.net> writes:

[...]

| int
| main()
| {
| 	int a = 2;
| 	A(a, a).foo();


[...]

| a.cxx:11: error: conflicting types for `A a'
| a.cxx:10: error: previous declaration as `int a'

This is a bug in the new parser.  Please fill a bug report.


-- Gaby

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: CVS head (gcc-3.4), problem with new parser?
  2002-12-31  3:47 ` Gabriel Dos Reis
@ 2002-12-31  6:36   ` Andrew Pollard
  2002-12-31  8:22   ` Andrew Pollard
  1 sibling, 0 replies; 5+ messages in thread
From: Andrew Pollard @ 2002-12-31  6:36 UTC (permalink / raw)
  To: gdr; +Cc: gcc


>Andrew Pollard <andrewp@andypo.net> writes:
>
>[...]
>
>| int
>| main()
>| {
>| 	int a = 2;
>| 	A(a, a).foo();
>
>[...]
>
>| a.cxx:11: error: conflicting types for `A a'
>| a.cxx:10: error: previous declaration as `int a'
>
>This is a bug in the new parser.  Please fill a bug report.

Will do. Just glad for the confirmation that it was a bug and not me
misunderstanding something :-)

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: CVS head (gcc-3.4), problem with new parser?
  2002-12-31  3:47 ` Gabriel Dos Reis
  2002-12-31  6:36   ` Andrew Pollard
@ 2002-12-31  8:22   ` Andrew Pollard
  1 sibling, 0 replies; 5+ messages in thread
From: Andrew Pollard @ 2002-12-31  8:22 UTC (permalink / raw)
  To: gdr; +Cc: gcc


Gabriel Dos Reis <gdr@integrable-solutions.net> replied:

>Andrew Pollard <andrewp@andypo.net> writes:
>
>[...]
>
>| int
>| main()
>| {
>| 	int a = 2;
>| 	A(a, a).foo();
>
>[...]
>
>| a.cxx:11: error: conflicting types for `A a'
>| a.cxx:10: error: previous declaration as `int a'
>
>This is a bug in the new parser.  Please fill a bug report.

Done. c++/9112.

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: CVS head (gcc-3.4), problem with new parser?
  2002-12-31  3:42 CVS head (gcc-3.4), problem with new parser? Andrew Pollard
  2002-12-31  3:47 ` Gabriel Dos Reis
@ 2002-12-31  9:17 ` Alexandre Oliva
  1 sibling, 0 replies; 5+ messages in thread
From: Alexandre Oliva @ 2002-12-31  9:17 UTC (permalink / raw)
  To: Andrew Pollard; +Cc: gcc

On Dec 31, 2002, Andrew Pollard <andrewp@andypo.net> wrote:

> which is all rather confusing... Is this what the standard indicates?

Except for the A(a,a) case, yes.

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                 aoliva@{redhat.com, gcc.gnu.org}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist                Professional serial bug killer

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2002-12-31 15:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-31  3:42 CVS head (gcc-3.4), problem with new parser? Andrew Pollard
2002-12-31  3:47 ` Gabriel Dos Reis
2002-12-31  6:36   ` Andrew Pollard
2002-12-31  8:22   ` Andrew Pollard
2002-12-31  9:17 ` Alexandre Oliva

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).