Strange GCC warning

H

Hendrik Schober

Hi,

this piece of code

namespace {
template< typename T >
struct X {};

template< typename T >
struct Y {};
}

namespace gaga {
struct Z : public Y< X<int> > {};
}

int main()
{
gaga::Z z;
return 0;
}

(which I didn't bother trying to simplify further) causes
some build of GCC 4.1.2 to emit the following warning:
'gaga::Z' has a base '<unnamed>::Y<<unnamed>::X<int> >' whose type uses the anonymous namespace
Has anyone out there any idea what GCC ist trying to tell
us?

Schobi

--
(e-mail address removed) is never read
I'm HSchober at gmx dot de
"If there were some arcane way to remove the heads of every
newsgroup troll on the planet, I think it would elevate
humans to a whole new level of intelligence."
Rocky Frisco
 
V

Victor Bazarov

Hendrik said:
Hi,

this piece of code

namespace {
template< typename T >
struct X {};

template< typename T >
struct Y {};
}

namespace gaga {
struct Z : public Y< X<int> > {};
}

int main()
{
gaga::Z z;
return 0;
}

(which I didn't bother trying to simplify further) causes
some build of GCC 4.1.2 to emit the following warning:
'gaga::Z' has a base '<unnamed>::Y<<unnamed>::X<int> >' whose type
uses the anonymous namespace Has anyone out there any idea what GCC
ist trying to tell us?

'Z' nas external linkage, so it should be accessible from another
module. However, it derives from classes that are not accessible
from another module (since they are in the anonymous namespace).
Perhaps it has something to do with that...

If not, please ask in the newsgroup dedicated to GCC or in their
online discussion forums.

V
 
A

Alf P. Steinbach

* Hendrik Schober:
Hi,

this piece of code

namespace {
template< typename T >
struct X {};

template< typename T >
struct Y {};
}

namespace gaga {
struct Z : public Y< X<int> > {};
}

int main()
{
gaga::Z z;
return 0;
}

(which I didn't bother trying to simplify further) causes
some build of GCC 4.1.2 to emit the following warning:
'gaga::Z' has a base '<unnamed>::Y<<unnamed>::X<int> >' whose type uses the anonymous namespace
Has anyone out there any idea what GCC ist trying to tell
us?

If the definitions before main were in a header file included in more
than one compilation unit, then gaga::Z would end up with multiple
/different/ definitions, because the the anonymous namespace would be
different anonymous namespaces in the different compilation units.

One solution is to put also Z in anonymous namespace.
 
H

Hendrik Schober

Alf P. Steinbach said:
* Hendrik Schober:
[GCC warning]

If the definitions before main were in a header file included in more
than one compilation unit, then gaga::Z would end up with multiple
/different/ definitions, because the the anonymous namespace would be
different anonymous namespaces in the different compilation units.

One solution is to put also Z in anonymous namespace.

Victor, Alf,

Thanks for the quick reply. I now see that there might be
some sense in that warning.

Here's some more info on the code (which seems important
now that I understand more about that warning).
There's a header containing something like this:
namespace gaga {
class A {
// ...
private:
struct Impl_;
Impl_* pimpl_;
};
}
This in is the matching cpp file:
namespace {
template< typename T > struct X {};
template< typename T > struct Y {};
}

namespace gaga {
struct A::Impl : public Y< X<int> > {};
// using 'A' and thus 'Impl_'
}
So, while I don't see how I can prevent 'A::Impl' from
having external linkage, with it being private I also
don't see how anyone could legally take advantage of
the fact that it's having external linkage and uses it.
Is there anything I miss or can we safely ignore that
warning?


P.S.: One build # of GCC 4.1.2 emits that warning,
one doesn't. Urgh.

--
(e-mail address removed) is never read
I'm HSchober at gmx dot de
"If there were some arcane way to remove the heads of every
newsgroup troll on the planet, I think it would elevate
humans to a whole new level of intelligence."
Rocky Frisco
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top