Commit 80a63a87 authored by Pawel Wodnicki's avatar Pawel Wodnicki
Browse files

Merging r168818: into the 3.2 release branch.

PR13098: If we're instantiating an overloaded binary operator and we could
determine which member function would be the callee from within the template
definition, don't pass that function as a "non-member function" to
CreateOverloadedBinOp. Instead, just rely on it to select the member function
for itself.

llvm-svn: 168830
parent edc2a45b
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -9179,7 +9179,12 @@ TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
    // IsAcceptableNonMemberOperatorCandidate for each of these?
    Functions.append(ULE->decls_begin(), ULE->decls_end());
  } else {
    Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
    // If we've resolved this to a particular non-member function, just call
    // that function. If we resolved it to a member function,
    // CreateOverloaded* will find that function for us.
    NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
    if (!isa<CXXMethodDecl>(ND))
      Functions.addDecl(ND);
  }

  // Add any functions found via argument-dependent lookup.
+31 −0
Original line number Diff line number Diff line
@@ -19,3 +19,34 @@ template <typename T> S_<NoDefinition>::type f(T*, NoDefinition*); // expected-n
void test(int x) {
  f(&x, 0);
}

// Ensure that we instantiate an overloaded function if it's selected by
// overload resolution when initializing a function pointer.
template<typename T> struct X {
  static T f() { T::error; } // expected-error {{has no members}}
  static T f(bool);
};
void (*p)() = &X<void>().f; // expected-note {{instantiation of}}

namespace PR13098 {
  struct A {
    A(int);
    void operator++() {}
    void operator+(int) {}
    void operator+(A) {}
    void operator[](int) {}
    void operator[](A) {}
  };
  struct B : A {
    using A::operator++;
    using A::operator+;
    using A::operator[];
  };
  template<typename T> void f(B b) {
    ++b;
    b + 0;
    b[0];
  }
  template void f<void>(B);
}