https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64169

            Bug ID: 64169
           Summary: Partial template specialization of reference-qualified
                    operator templates
           Product: gcc
           Version: 4.9.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: knoepfel at fnal dot gov

System : x86_64-apple-darwin13.4.0
options: -Wall -Wextra
std    : c++1y

The preprocessed version of the below code looks identical except for the
#include <iostream> contents.

Consider the following code where I attempt to specialize the &-qualified
version of operator <<.

BEGIN_CODE

namespace {

  template <typename T>
  class A {
  public:

    template < typename U> A&& operator << ( U const & ) && {
      std::cerr << "... && version\n";
      return std::move(*this);
    }

    template <typename U> A& operator << ( U const &) & {
      std::cerr << "... &  version\n";
      return *this;
    }

  };


  template<>
  template<typename U>
  A<int>& A<int>::operator<< ( U const & ) & {
    std::cerr << "... &  version (int)\n";
    return *this;
  }

}


int main() {

  A<double>() << "";
  A<double> adouble;
  adouble << "";

  A<int>() << "";
  A<int> aint;
  aint << "";

}

END_CODE

The gcc compile errors are:

ref-qualified-operators.cpp:25:11: error: ambiguous template specialization
‘operator<< <>’ for ‘{anonymous}::A<int>& {anonymous}::A<int>::operator<<(const
U&) &’
   A<int>& A<int>::operator<< ( U const & ) & {
           ^
ref-qualified-operators.cpp:10:32: note: candidates are: template<class U>
{anonymous}::A<T>&& {anonymous}::A<T>::operator<<(const U&) && [with U = U; T =
int]
     template < typename U> A&& operator << ( U const & ) && { 
                                ^
ref-qualified-operators.cpp:15:30: note:                 template<class U>
{anonymous}::A<T>& {anonymous}::A<T>::operator<<(const U&) & [with U = U; T =
int]
     template <typename U> A&  operator << ( U const &) &  { 
                              ^

The above code is accepted by clang 3.5 and outputs:

... && version
... &  version
... && version
... &  version (int)

Reply via email to