[gnu.gcc.bug] typedef and object name spaces

riedl@CS.PURDUE.EDU (John Riedl) (09/19/89)

gcc allows typedef's to be used to declare variables in an inner scope
with the same name as a typedef from the outer scope.  This seems to
agree with the letter of the ansi standard (I only have K&R's new
book), but has the problems that it only works the first time (after
that the new variable replaces the typedef in the namespace) and that
the code is unlikely to compile under other C compilers.  I have
attached a short program exhibiting the behaviour that caught me.  I
suggest that this is a common mistake for a beginner to make,
especially because the name spaces for objects and struct/union tags
are separate.  The Sun C compiler complains about the declaration,
which helps the programmer.  At the least, gcc should complain in
-pedantic mode.

Thanks,
John Riedl
{ucbvax,decvax,hplabs}!purdue!riedl  -or-  riedl@cs.purdue.edu

-------
typedef int X;

main()
{
  X X;		/* this works */
  X Y;		/* X has been redefined, so this fails */
}
---------