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

            Bug ID: 63609
           Summary: incompatibility with C++11 standard on 14.5.6.2
                    Partial ordering of function templates
           Product: gcc
           Version: 4.8.3
            Status: UNCONFIRMED
          Severity: blocker
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dccmmccd1 at gmail dot com

The following example is taken (with small modifications to make it compile)
from http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3242.pdf 14.5.6.2
(item 3) :

#include <iostream>

struct A {};

template<class T>
struct B {
  template<class R> void operator*(R&) { // #1
    std::cout << "1" << std::endl;
  }
};

template<class T, class R>
void operator*(T&, R&) {  // #2
  std::cout << "2" << std::endl;
}

int main() {
  A a;
  B<A> b;
  b * a; //should print 1
}

Unless this was removed from the final c++11 standard I believe this has to be
legal c++ code, but g++ (4.8.3) gives the following error:
test_templates.cpp: In function ‘int main()’:
test_templates.cpp:20:5: error: ambiguous overload for ‘operator*’ (operand
types are ‘B<A>’ and ‘A’)
   b * a; //should print 1
     ^
test_templates.cpp:20:5: note: candidates are:
test_templates.cpp:7:26: note: void B<T>::operator*(R&) [with R = A; T = A]
   template<class R> void operator*(R&) {       // #1
                          ^
test_templates.cpp:13:6: note: void operator*(T&, R&) [with T = B<A>; R = A]
 void operator*(T&, R&) {  // #2

Reply via email to