By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,781 Members | 1,387 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,781 IT Pros & Developers. It's quick & easy.

Strange GCC warning

P: n/a
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

--
Sp******@gmx.de 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
Jul 31 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hendrik Schober wrote:
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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 31 '07 #2

P: n/a
Alf P. Steinbach <al***@start.nowrote:
* 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.

--
Sp******@gmx.de 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
Jul 31 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.