[Bug c++/31187] New: [4.2 regression] extern declaration of variable in anonymous namespace prevents use of its address as template argument

Gabriel Dos Reis gdr@cs.tamu.edu
Fri Mar 16 15:15:00 GMT 2007


"zak at transversal dot com" <gcc-bugzilla@gcc.gnu.org> writes:

| The following code, which compiles fine on gcc 4.1.2 and I believe is valid,
| fails on an up-to-date checkout from the 4.2 branch:
| 
| --------------------------------------
| class foo { };
| 
| namespace
| {
|         extern foo foo1;
|         foo foo1;
| }
| 
| template< foo * >
| class bar { };
| 
| bar< &foo1 > bar1;
| ---------------------------------------
| 
| giving the error:
| 
| test.cc:12: error: '&<unnamed>::foo1' is not a valid template argument of type
| 'foo*' because '<unnamed>::foo1' does not have external linkage
| test.cc:12: error: invalid type in declaration before ';' token
| 
| 
| ... which I would only expect if "foo1" were declared "static".

Yes, this is a bug in the compiler.  I suspect it was introduced when
the the back was told to treat declarations at unnamed namespaces
ast static.  That of course is an optimization and should be appear at
the front-end.

-- gaby



More information about the Gcc-bugs mailing list