Strange GCC warning

Discussion in 'C++' started by Hendrik Schober, Jul 31, 2007.

  1. 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

    --
    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
     
    Hendrik Schober, Jul 31, 2007
    #1
    1. Advertisements

  2. '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
     
    Victor Bazarov, Jul 31, 2007
    #2
    1. Advertisements

  3. * Hendrik Schober:
    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.
     
    Alf P. Steinbach, Jul 31, 2007
    #3
  4. 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.

    --
    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
     
    Hendrik Schober, Jul 31, 2007
    #4
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.