• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Problem with friend function and gcc 4.2 with
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem with friend function and gcc 4.2 with


  • Subject: Re: Problem with friend function and gcc 4.2 with
  • From: "Roni Music" <email@hidden>
  • Date: Sun, 10 Aug 2008 22:13:34 +0200


You can read a discussion regarding this problem here: http://bytes.com/forum/thread828536.html

it seems gcc 4.0 had a bug which is corrected in gcc 4.2


Message: 12
Date: Sat, 9 Aug 2008 09:36:17 -0600
From: Ken Worley <email@hidden>
Subject: Re: Problem with friend function and gcc 4.2 with
To: cocoa-dev cocoa-dev <email@hidden>
Cc: Roni Music <email@hidden>
Message-ID: <email@hidden>
Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes

FWIW, it does in fact compile in 4.2 (and in 4.0) when formatted as
you suggest. I still believe the original format is correct and that
4.2 is the version with the bug. The info Clark Cox pointed out seems
to support that. In any case, a bug has been filed, so I'll know
Apple's point of view eventually :) Thanks for the input (and thanks
also to Clark and Thomas for responding).

rdar://6135771

Ken

On Aug 8, 2008, at 10:42 PM, Roni Music wrote:


I'm not a C++ expert but your code below should not compile (as I see it)

You should declare the friend function inside the class:

class test1
{
public:

friend test1* newtest1(int x);
/*
the function newtest1() is now a friend to test1 class and may
access private member variables
and functions such as finishinit()
*/

snip....
};

then define the function outside the class:

test1* newtest1(int x)
{
test1* anobj = new test1();
anobj->finishinit(x);
return anobj;
}

So if you code worked with gcc 4.0 and not gcc 4.2, then it seems
gcc 4.2 now works according to the C++ standard
and gcc 4.0 did not

Rolf




Message: 10
Date: Fri, 8 Aug 2008 16:41:42 -0600
From: Ken Worley <email@hidden>
Subject: Re: Problem with friend function and gcc 4.2 with
objective-c++
To: cocoa-dev cocoa-dev <email@hidden>
Message-ID: <email@hidden>
Content-Type: text/plain; charset=WINDOWS-1252; format=flowed;
delsp=yes

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 (email@hidden)

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:
This email sent to email@hidden

-- Ken Worley Software Engineer, Tiberius, Inc.






-- Ken Worley Software Engineer, Tiberius, Inc.





------------------------------

_______________________________________________

Cocoa-dev mailing list      (email@hidden)

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

http://lists.apple.com/mailman/listinfo/cocoa-dev


End of Cocoa-dev Digest, Vol 5, Issue 1422 ******************************************


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Problem with friend function and gcc 4.2 with
      • From: Ken Worley <email@hidden>
  • Prev by Date: Hillegass' chapter #11: Core Data
  • Next by Date: Re: including a cocoa bundle in a carbon app
  • Previous by thread: Re: Problem with friend function and gcc 4.2 with
  • Next by thread: Re: Problem with friend function and gcc 4.2 with
  • Index(es):
    • Date
    • Thread