Re: Compile error in GCC but not other compilers
Re: Compile error in GCC but not other compilers
- Subject: Re: Compile error in GCC but not other compilers
- From: Ronald Fenner <email@hidden>
- Date: Tue, 23 May 2006 20:39:10 -0500
On May 15, 2006, at 4:57 PM, Duane Murphy wrote:
--- At Mon, 15 May 2006 17:15:55 -0400, Howard Hinnant wrote:
On May 15, 2006, at 3:08 PM, James W. Walker wrote:
One of my problems in porting from CodeWarrior to Xcode boils down
to the code below:
namespace
{
class xxx
{
xxx();
};
}
class yyy
{
friend class xxx;
};
xxx::xxx()
{
}
Xcode says:
error: 'xxx' has not been declared
error: ISO C++ forbids declaration of 'xxx' with no type
CodeWarrior has no problem with this code, nor does the Comeau
online compiler test page. So, is this a bug in GCC?
This looks like a bug to me. You could pop "::" unto xxx in the
friend statement to workaround:
friend class ::xxx;
Unfortunately it isn't a very good workaround because it is now
illegal C++ code. :-(
I've hit this myself and scratched my head.
Can you explain why
friend class ::xxx;
is also illegal?
...Duane
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
Actually it's not illegal C++ as your using the scope operator to
tell the compiler to look for the class in the global namespace.
I hit this one myself with my unit testing classes since I didn't
stick them inside of a namespace.
I had done this:
#ifdef UNIT_TESTING__
class SomeClassTest;
#endif
then down in the class that the unit test needed access to, that was
inside of a namespace I had:
#ifdef UNIT_TESTING__
friend class SomeTestClass;
#endif
Xcode would give the error your running into but under MSVC I
wouldn't have a problem.
I found that If i put the unit test class inside of a namespace and
then changed the code to this:
namespace SOME_NAMESPACE {
#ifdef UNIT_TESTING__
class SomeClassTest;
#endif
}
and:
#ifdef UNIT_TESTING__
friend class SOME_NAMESPACE::SomeTestClass;
#endif
That it would then compile. If i removed the namespace but told the
compiler to look in the global namespace with :: it worked ok. MSVC
doesn't have a problem with the changed code either.
The bug here seems to be that the compiler doesn't look outside of
the namespace that a class may be wrapped in, to any other namespace
that be around the one where you declare the friend. This bug forces
you to explicitly tell it what namespace to find the friend in.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden