Conflicts with Nested Namespaces

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Hamish

    Conflicts with Nested Namespaces

    Consider the following code:

    #include <iostream>

    typedef int Thingo;

    namespace A
    {
    namespace B
    {
    void
    Thingo();
    }
    }

    void
    A::B::Thingo()
    {
    std::cout << "Reached: void A::B::Thingo()" << std::endl;
    }

    int
    main()
    {
    A::B::Thingo();
    return 0;
    }

    This code generates the following error on g++ versions 3.2.2 and
    2.96:

    $ g++ test.cc
    test.cc: In function `void A::B::Thingo()' :
    test.cc:16: `void A::B::Thingo()' redeclared as different kind of symbol
    test.cc:3: previous declaration of `typedef int Thingo'

    The error goes away if:
    - you wrap the typedef in an anonymous namespace;
    - you use 'struct B' instead of 'namespace B'; or
    - you include the definition of void A::B::Thingo() either
    namespace A or B.
    - you replace the typedef with struct Thingo {};

    The error remains if:
    - you replace the typedef with enum { Thingo };


    Could someone please explain what is wrong with the code. For the life
    of me I can't figure out why it's unacceptable.

    Thanks in advance,
    Hamish.
  • Rolf Magnus

    #2
    Re: Conflicts with Nested Namespaces

    Hamish wrote:
    [color=blue]
    > Could someone please explain what is wrong with the code. For the
    > life of me I can't figure out why it's unacceptable.[/color]

    I don't see why there should a conflict, and comeau online compiles it
    without errors, so I suspect a bug in g++ 3.2.2

    Comment

    • stephan beal

      #3
      Re: Conflicts with Nested Namespaces

      Hamish wrote:[color=blue]
      > Consider the following code:
      > typedef int Thingo;
      > namespace A
      > {
      > namespace B
      > {
      > void
      > Thingo();
      > }
      > }
      > This code generates the following error on g++ versions 3.2.2 and
      > 2.96:
      >
      > $ g++ test.cc
      > test.cc: In function `void A::B::Thingo()' :
      > test.cc:16: `void A::B::Thingo()' redeclared as different kind of symbol
      > test.cc:3: previous declaration of `typedef int Thingo'[/color]

      i've seen similar errors from gcc 3.3pre, but i don't have a solution.
      Regaring 2.96: ONLY RedHat released that version - GNU never did, so it is
      not to be trusted, IMO. If you'll look on ftp.gnu.org you'll not find a
      copy of 2.96.


      --
      ----- stephan beal
      Registered Linux User #71917 http://counter.li.org
      I speak for myself, not my employer. Contents may
      be hot. Slippery when wet. Reading disclaimers makes
      you go blind. Writing them is worse. You have been Warned.

      Comment

      • Hamish Ivey-Law

        #4
        Re: Conflicts with Nested Namespaces

        In article <bmlv7o$bkr$1@o rk.noris.net>, stephan beal wrote:[color=blue]
        > Regaring 2.96: ONLY RedHat released that version - GNU never did, so it is
        > not to be trusted, IMO. If you'll look on ftp.gnu.org you'll not find a
        > copy of 2.96.[/color]

        I'm well aware of that; I'm lead to believe that RedHat included gcc 2.96
        (the internal gcc developers' codename for the upcoming 3.x series) in their
        7.2 release because they needed a compiler that supported the ia64 chips.
        The only reason I've used that compiler at all is because I was forced to
        do some development on that acursed 7.2 platform. Nothing worked properly.

        --
        Hamish

        Comment

        • Hamish

          #5
          Re: Conflicts with Nested Namespaces

          In article <bmloqg$6tc$07$ 1@news.t-online.com>, Rolf Magnus wrote:[color=blue]
          >
          > Hamish wrote:
          >[color=green]
          > > Could someone please explain what is wrong with the code. For the
          > > life of me I can't figure out why it's unacceptable.[/color]
          >
          > I don't see why there should a conflict, and comeau online compiles it
          > without errors, so I suspect a bug in g++ 3.2.2[/color]

          I was fearing that. It didn't come up in my searches of the gcc bug
          archives either.

          --
          Hamish

          Comment

          Working...