public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Errors using the same identifier as type and function name
@ 2008-09-01 23:59 Rodolfo Lima
  2008-09-02  1:00 ` John Fine
  0 siblings, 1 reply; 4+ messages in thread
From: Rodolfo Lima @ 2008-09-01 23:59 UTC (permalink / raw)
  To: gcc-help

Hi, I wonder why the following code gives the error below with
gcc-3.4.6 up to 4.3.1 (I don't know about earlier versions):

struct type {};

struct A
{
     type *type() { return 0; }
};

teste.cpp:5: error: declaration of 'type* A::type()'
teste.cpp:1: error: changes meaning of 'type' from 'struct type'

If we define 'A' as

struct A : type
{
     type *type() { return 0; }
};

it compiles fine.

I've searched the C++2003 standard for something related to this but 
couldn't find anything. Anyone knows what's happening here?

IMHO it should compile because 'A::type' is in a different scope of 
'struct type', and the fact that we're referencing 'struct type' 
*before* specifying 'A::type' function name shouldn't make both 
identifiers ambiguous.

Regards,
Rodolfo Lima

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

* Re: Errors using the same identifier as type and function name
  2008-09-01 23:59 Errors using the same identifier as type and function name Rodolfo Lima
@ 2008-09-02  1:00 ` John Fine
  2008-09-02  1:12   ` Rodolfo Lima
  0 siblings, 1 reply; 4+ messages in thread
From: John Fine @ 2008-09-02  1:00 UTC (permalink / raw)
  To: Rodolfo Lima; +Cc: gcc-help



Rodolfo Lima wrote:
>   the fact that we're referencing 'struct type' *before* specifying 
> 'A::type' function name shouldn't make both identifiers ambiguous.
>
>
Sequence doesn't work that way when declaring members.  Inside a struct 
definition, you can use a member name before declaring it.


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

* Re: Errors using the same identifier as type and function name
  2008-09-02  1:00 ` John Fine
@ 2008-09-02  1:12   ` Rodolfo Lima
  2008-09-02 12:11     ` Marco Manfredini
  0 siblings, 1 reply; 4+ messages in thread
From: Rodolfo Lima @ 2008-09-02  1:12 UTC (permalink / raw)
  To: gcc-help

John Fine escreveu:
> Sequence doesn't work that way when declaring members.  Inside a struct 
> definition, you can use a member name before declaring it.

That's a valid point, but why it compiles when we inherit 'struct A' 
from 'struct type'? That's what bugged me in the first place.

Regards,
Rodolfo Lima

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

* Re: Errors using the same identifier as type and function name
  2008-09-02  1:12   ` Rodolfo Lima
@ 2008-09-02 12:11     ` Marco Manfredini
  0 siblings, 0 replies; 4+ messages in thread
From: Marco Manfredini @ 2008-09-02 12:11 UTC (permalink / raw)
  To: gcc-help

On Tuesday 02 September 2008, Rodolfo Lima wrote:
> John Fine escreveu:
> > Sequence doesn't work that way when declaring members.  Inside a struct
> > definition, you can use a member name before declaring it.
>
> That's a valid point, but why it compiles when we inherit 'struct A'
> from 'struct type'? That's what bugged me in the first place.

I think that's because the clauses about illegally changing the meaning of a 
names come from the shady mists of the standard's 3.3.6(2,3), which does not 
require the compiler to issue any diagnostics.

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

end of thread, other threads:[~2008-09-02 12:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-09-01 23:59 Errors using the same identifier as type and function name Rodolfo Lima
2008-09-02  1:00 ` John Fine
2008-09-02  1:12   ` Rodolfo Lima
2008-09-02 12:11     ` Marco Manfredini

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).