Mysterious namespace and typedef interactions

stephen.webb@cybersafe.com stephen.webb@cybersafe.com
Fri Feb 23 09:02:00 GMT 2001


I'm getting seemingly bizarre interactions between namespaces and typedefs using the CVS source (20010219 on Solaris
2.6, 20010222 on Solaris 2.8).  I'm not sure if it's a bug or I (as is often the case) am failing to understand some
subtlety of the language.

I've boiled down the problem to the following file whittled from preprocessed source, consisting of lines from
Solaris system header files.  

// fails with "c++ -c bull.cpp"
namespace _C_legacy {
	typedef struct __FILE __FILE;
	typedef int ssize_t;

	struct __FILE
	{
		ssize_t _cnt;
	};
}
// gives error "bull.cpp:7: syntax error before `;' token"                                                  
      
The following two variants will compile.

// no forward reference typedef
namespace _C_legacy {
	typedef int ssize_t;

	struct __FILE
	{
		ssize_t _cnt;
	};
}

// namespace qualification
namespace _C_legacy {
	typedef struct __FILE __FILE;
	typedef int ssize_t;

	struct __FILE
	{
		_C_legacy::ssize_t _cnt;
	};
}


It seems to me that if this is not a bug, a lot of existing code is going to break.  The error does not occur with
gcc 2.95.2 or the Solaris WS6 C++ compiler.



Stephen M. Webb



More information about the Gcc-bugs mailing list