This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: g++ doesn't accept AIX include file


> I read Bjarne Stroustrup: The C++ Programming Language, Second Edition,
> section r.7.1.3 The typedef Specifier. It says among other things:
> 
> "An unnamed class defined in a typedef gets its typedef name as its name.
> For example,
> 
>   typedef struct { (* ... */ } S; // the struct is named S"

Thanks for your bug report. The exact wording in the standard is, from
7.1.3, [dcl.typedef]/3

# If the typedef declaration defines an unnamed class (or enum), the
# first typedef­name declared by the declaration to be that class type
# (or enum type) is used to denote the class type (or enum type) for
# linkage purposes only (3.5).

They then have the (informal)

# [Note: if the typedef­name is used where a class­name (or enum­name)
# is required, the program is ill­formed.For example, 
#
# typedef struct { 
#  S(); //error: requires a return type because S is
#       // an ordinary member function, not a constructor 
# } S; 
# -- end note]

So the name is for linkage purposes *only*. That is, when you have

void foo(S*);
void foo(int);

in one translation unit, and 

void foo(S*){}

in another, than the definition above refers to the first declaration.

You cannot use the name in an elaborated-type-specifier, since that
would require a class-name.

Hope this helps,
Martin

P.S. If you are not satisfied with this answer, please discuss the
issue in comp.std.c++ first.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]