Home Ambiguous operator overload in Clang
Reply: 0

Ambiguous operator overload in Clang

user974
1#
user974 Published in April 24, 2018, 8:35 am

Consider the following:

template<typename T>
struct C {};
template<typename T, typename U>
void operator +(C<T>&, U);

struct D: C<D> {};

struct E {};
template<typename T>
void operator +(C<T>&, E);

void F() { D d; E e; d + e; }

This code compiles fine on both GCC-7 and Clang-5. The selected overload for operator + is that of struct E.

Now, if the following change takes place:

/* Put `operator +` inside the class. */
template<typename T>
struct C {
    template<typename U>
    void operator +(U);
};

that is, if operator + is defined inside the class template, instead of outside, then Clang yields ambiguity between both operator +s present in the code. GCC still compiles fine.

Why does this happen? Is this a bug in either GCC or Clang?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.456937 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO