Topic: A (too) simple question about names


Author: sdouglass@armltd.co.uk (scott douglass)
Date: 1995/12/06
Raw View
=46irst the context:  I was trying to decide from the draft standard if the
following code is legal:

void f()
    {
    struct s { int s; };
    typedef s x;
    int x;
    x =3D 5;
    }

The question is whether 'typedef s x;' clashes with 'int x;'.

>From [Oct draft] section 3.3.7, Name hiding, we find:

2 A class name (_class.name_) or enumeration name  (_dcl.enum_)  can  be
  hidden  by  the name of an object, function, or enumerator declared in
  the same scope.  If a class or enumeration name and an  object,  func=82
  tion, or enumerator are declared in the same scope (in any order) with
  the same name, the class or enumeration name is  hidden  wherever  the
  object, function, or enumerator name is visible.

And in section 7.1.3, The typedef specifier, we find:

4 A typedef-name that names a class is a class-name (_class.name_).

Which seems to allow the above program.

But what if we change the typedef to, say, 'typedef long x;'?  'x' is no
longer a <class-name> so this is no longer allowed by 3.3.7.

So here's the real question:  When can two <entities> in the same scope
have the same name?

"Everyone knows" that:

extern int f;
extern void f();

is ill-formed but where does the standard say it?  I and some friends
looked through sections 3, 7 and 8 but we didn't find anything
satisfactory.  [I admit it could still be hiding in there somewhere.]

Can you set me straight?  Thanks,

                 --scott



[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]