This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/32204] friend from global namespace in template class ignored


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32204

etherice <scottbaldwin at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |scottbaldwin at gmail dot
                   |                            |com

--- Comment #7 from etherice <scottbaldwin at gmail dot com> 2012-10-27 08:11:45 UTC ---
As Jonathan explains in comment #5, gcc is right to reject this code and MSVC
is wrong to accept it. You will have to add a forward declaration of the
class/function in order to declare it as a friend in the namespaced class. For
example:

// on gcc 4.7.0 (linux), these forward declarations are required for the friend
declarations in ns::NamespacedClass
class GlobalClass;
void globalFunction();

namespace ns {
    struct NamespacedClass {
        friend ::GlobalClass; // same result whether '::' or 'class' is part of
declaration
        friend void ::globalFunction();
    private:
        NamespacedClass() {}
    };
}

struct GlobalClass {
    GlobalClass() { ns::NamespacedClass foo; }
};

void globalFunction() {
    ns::NamespacedClass foo;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]