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

Joshua Root jmr at macports.org
Sun Aug 18 01:45:28 PDT 2013


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.

- Josh


More information about the macports-dev mailing list