Conflicts with Nested Namespaces

H

Hamish

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

Rolf Magnus

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

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
 
S

stephan beal

Hamish said:
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'

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

Hamish Ivey-Law

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.

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

Hamish

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

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

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,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top