that function, and apart from being slow, this is unnecessary: ADL can trigger
instantiations that are not permitted here. The standard isn't *completely*
clear here, but this seems like the intent, and in any case this approach is
permitted by [temp.inst]p7.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@218330
91177308-0d34-0410-b5e6-
96231b3b80d8
UnresolvedSet<16> Functions;
OverloadedOperatorKind OverOp
= BinaryOperator::getOverloadedOperator(Opc);
- if (Sc && OverOp != OO_None)
+ if (Sc && OverOp != OO_None && OverOp != OO_Equal)
S.LookupOverloadedOperatorName(OverOp, Sc, LHS->getType(),
RHS->getType(), Functions);
// Add operator candidates that are member functions.
AddMemberOperatorCandidates(Op, OpLoc, Args, CandidateSet);
- // Add candidates from ADL.
- AddArgumentDependentLookupCandidates(OpName, OpLoc, Args,
- /*ExplicitTemplateArgs*/ nullptr,
- CandidateSet);
+ // Add candidates from ADL. Per [over.match.oper]p2, this lookup is not
+ // performed for an assignment operator (nor for operator[] nor operator->,
+ // which don't get here).
+ if (Opc != BO_Assign)
+ AddArgumentDependentLookupCandidates(OpName, OpLoc, Args,
+ /*ExplicitTemplateArgs*/ nullptr,
+ CandidateSet);
// Add builtin operator candidates.
AddBuiltinOperatorCandidates(Op, OpLoc, Args, CandidateSet);
// dr220: na
namespace dr221 { // dr221: yes
- struct A {
- A &operator=(int&);
+ struct A { // expected-note 2-4{{candidate}}
+ A &operator=(int&); // expected-note 2{{candidate}}
A &operator+=(int&);
static A &operator=(A&, double&); // expected-error {{cannot be a static member}}
static A &operator+=(A&, double&); // expected-error {{cannot be a static member}}
void test(A a, int n, char c, float f) {
a = n;
a += n;
- a = c;
+ a = c; // expected-error {{no viable}}
a += c;
- a = f;
+ a = f; // expected-error {{no viable}}
a += f;
}
}
int x = a;
int y = b;
}
+
+namespace NoADLForMemberOnlyOperators {
+ template<typename T> struct A { typename T::error e; }; // expected-error {{type 'char' cannot be used prior to '::'}}
+ template<typename T> struct B { int n; };
+
+ void f(B<A<void> > b1, B<A<int> > b2, B<A<char> > b3) {
+ b1 = b1; // ok, does not instantiate A<void>.
+ (void)b1->n; // expected-error {{is not a pointer}}
+ b2[3]; // expected-error {{does not provide a subscript}}
+ b3 / 0; // expected-note {{in instantiation of}} expected-error {{invalid operands to}}
+ }
+}