A C++ question: when to use "friend class"/"friend template"

Mojca Miklavec mojca at macports.org
Mon Sep 9 11:14:41 PDT 2013


Dear Josh,

On Sun, Aug 18, 2013 at 10:45 AM, Joshua Root wrote:
> On 2013-8-18 16:55 , Mojca Miklavec wrote:
>> Hello,
>>
>> While this might not be the most appropriate list to ask this type
>> questions, I hope that there is someone who might be able to help.
>>
>> When trying to upgrade a port (hugin-app in particular) I had to
>> modify the following code:
>>
>>  #ifdef __GNUC__
>>  friend class Notify::self_type;
>>  #else
>>  friend typename Notify::self_type;
>>  #endif
>>
>> The Clang compiler (Xcode Xcode 4.6.3 on Lion) failed to work with
>> "friend class Notify::self_type;". As a temporary patch I removed
>> #ifdef and made the compiler always end up seeing the code "friend
>> typename Notify::self_type;", but I believe that this will break the
>> gcc compilers (I didn't try though because compilation takes forever).
>>
>> Does anyone know what the proper patch should be?
>>
>> Thank you,
>>     Mojca
>>
>> PS: the latest version of hugin-app claims to work with wxWidgets 2.9
>> even though it's stated to be experimental. But most problems with
>> compiling that new version arise from linking to boost.
>
> It's hard to infer what the code is trying to accomplish from that one
> snippet. But AIUI 'friend typename' is not valid in standards prior to
> C++11. And if self_type is not in fact a class, declaring it to be one
> here may well result in undefined behaviour.

Does this patch seem reasonable to you?

http://sourceforge.net/p/hugin/hugin/ci/752123441af3ca9d1977081b59f480b9a161247f/
https://bugs.launchpad.net/hugin/+bug/1213586

(I don't have sufficient experience with C++ (compilers) to be able to
judge. They asked for testing.)

Mojca


More information about the macports-dev mailing list