Just to close this out, it was confirmed that the current behavior in 4.2 is correct. The flag -ffriend-injection can be used to work around it (i.e. retain the old 4.0 behavior), but fixing the code is the better route.

Ken

On Aug 8, 2008, at 4:41 PM, Ken Worley wrote:

Hmmm, no response as of yet. I went ahead and submitted a bug against Xcode: rdar://6135771
We'll see what happens.

Ken
On Aug 7, 2008, at 4:09 PM, Ken Worley wrote:

Hi all,

I'm using Xcode 3.1 and just switched to gcc 4.2 from 4.0, but I've run into a problem with friend functions when compiling in objective-c++. I contrived an example that illustrates the problem:

1. Created new Cocoa project
2. Forced compilation of all files to use objective-c++
3. Changed content of main.m to below...

This project builds fine using gcc 4.0, but when I switch the compiler setting to use gcc 4.2, I get the errors listed below. Any clues would certainly be appreciated if I'm doing something wrong. If not, I guess I'll file a bug...

Here's main.m:

#import <Cocoa/Cocoa.h>

class test1
{
        public:
        
                friend test1* newtest1(int x)
                {
                        test1* anobj = new test1();
                        anobj->finishinit(x);
                        return anobj;
                }
                
                virtual ~test1()
                {
                }
                
        private:
                
                int     avalue;
                
                test1()
                {
                        avalue = 0;
                }
                
                void finishinit(int x)
                {
                        avalue = x;
                }
};

int main(int argc, char *argv[])
{
        test1* tobj = newtest1(5);
        delete tobj;
        
  return NSApplicationMain(argc,  (const char **) argv);
}


Here's the build log:

Building target “Untitled” of project “Untitled” with configuration “Debug” — (1 error)
            cd /Users/ken/Desktop/Untitled
/Xcode3.1/Developer/usr/bin/gcc-4.2 -x objective-c++ -arch i386 - fmessage-length=0 -pipe -Wno-trigraphs -fpascal-strings -fasm- blocks -O0 -Wreturn-type -Wunused-variable -isysroot /Xcode3.1/ Developer/SDKs/MacOSX10.5.sdk -mfix-and-continue -fvisibility- inlines-hidden -mmacosx-version-min=10.5 -gdwarf-2 -iquote /Users/ ken/Desktop/Untitled/build/Untitled.build/Debug/Untitled.build/ Untitled-generated-files.hmap -I/Users/ken/Desktop/Untitled/build/ Untitled.build/Debug/Untitled.build/Untitled-own-target- headers.hmap -I/Users/ken/Desktop/Untitled/build/Untitled.build/ Debug/Untitled.build/Untitled-all-target-headers.hmap -iquote / Users/ken/Desktop/Untitled/build/Untitled.build/Debug/ Untitled.build/Untitled-project-headers.hmap -F/Users/ken/Desktop/ Untitled/build/Debug -I/Users/ken/Desktop/Untitled/build/Debug/ include -I/Users/ken/Desktop/Untitled/build/Untitled.build/Debug/ Untitled.build/DerivedSources -include /var/folders/JE/ JEJ3RSLHE9uIDGjXTRTis++++TI/-Caches-/com.apple.Xcode.501/ SharedPrecompiledHeaders/Untitled_Prefix- brblicjbwwpqhfahflncgqpvarno/Untitled_Prefix.pch -c /Users/ken/ Desktop/Untitled/main.m -o /Users/ken/Desktop/Untitled/build/ Untitled.build/Debug/Untitled.build/Objects-normal/i386/main.o /Users/ken/Desktop/Untitled/main.m: In function 'int main(int, char**)': /Users/ken/Desktop/Untitled/main.m:43: error: 'newtest1' was not declared in this scope /Users/ken/Desktop/Untitled/main.m:43: error: 'newtest1' was not declared in this scope
Build failed (1 error)

Thanks,
Ken

--
Ken Worley
Software Engineer, Tiberius, Inc.



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/cocoadev%40tiberiusinc.com

This email sent to [EMAIL PROTECTED]

--
Ken Worley
Software Engineer, Tiberius, Inc.



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/cocoadev%40tiberiusinc.com

This email sent to [EMAIL PROTECTED]

--
Ken Worley
Software Engineer, Tiberius, Inc.



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to