GCC claims friend function is overloaded, ambiguous call, compilation clang

template <typename T>
class rp {
};

template <template <typename> class P>
struct b {
    template <class, template <typename> class FriendP>
    friend void f(b<FriendP> from);
};

template <class, template <typename> class P>
void f(b<P> from) {
}

int main() {
    b<rp> v;
    f<int>(v);
    return 0;
}

Clang 3.3 (svn) compiles fine, and GCC 4.8 rejects it:

main.cpp: In function 'int main()':
main.cpp:17:10: error: call of overloaded 'f(b<rp>&)' is ambiguous
  f<int>(v);
          ^
main.cpp:17:10: note: candidates are:
main.cpp:12:6: note: void f(b<P>) [with <template-parameter-1-1> = int; P = rp]
 void f(b<P> from) {
      ^
main.cpp:8:17: note: void f(b<FriendP>) [with <template-parameter-2-1> = int; FriendP = rp; P = rp]
     friend void f(b<FriendP> from);
                 ^

I wonder why the GCC claims to be foverloaded. Therefore, I assume this is a GCC error.

Which compiler is right?

+5
source share
1 answer

Friend-injection no longer exists in the C ++ standard; see this for information on this. However, since the friend function declared inside struct b "acts" on a parameter of type "b", the function is found via ADL (search dependent on the argument). When this happens, two different functions are declared that have the same signature, and the compiler complains.

, , , :

template <template <typename> class P>
struct b {
    template <class, template <typename> class FriendP>
    friend void f(b<FriendP> from){};
};

, " " , , ( ).

( , ) - 46 ++

+1

All Articles