From: Richard Smith Date: Wed, 28 Nov 2012 21:47:39 +0000 (+0000) Subject: PR13098: If we're instantiating an overloaded binary operator and we could X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f641166066c7053300cada4ca5c9e69ad1cd2358;p=clang 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@168818 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h index 72175dea51..ac66bcf455 100644 --- a/lib/Sema/TreeTransform.h +++ b/lib/Sema/TreeTransform.h @@ -9180,7 +9180,12 @@ TreeTransform::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, // IsAcceptableNonMemberOperatorCandidate for each of these? Functions.append(ULE->decls_begin(), ULE->decls_end()); } else { - Functions.addDecl(cast(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(Callee)->getDecl(); + if (!isa(ND)) + Functions.addDecl(ND); } // Add any functions found via argument-dependent lookup. diff --git a/test/SemaTemplate/instantiate-overload-candidates.cpp b/test/SemaTemplate/instantiate-overload-candidates.cpp index 5c892aab37..7542dbd8ab 100644 --- a/test/SemaTemplate/instantiate-overload-candidates.cpp +++ b/test/SemaTemplate/instantiate-overload-candidates.cpp @@ -27,3 +27,25 @@ template struct X { static T f(bool); }; void (*p)() = &X().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 void f(B b) { + ++b; + b + 0; + b[0]; + } + template void f(B); +}