Skip to content

Commit

Permalink
PR44627: Consider reversing == and <=> candidates found by ADL.
Browse files Browse the repository at this point in the history
  • Loading branch information
zygoloid committed Jan 31, 2020
1 parent c6cf360 commit 1db66e7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
30 changes: 22 additions & 8 deletions clang/lib/Sema/SemaOverload.cpp
Expand Up @@ -9278,17 +9278,31 @@ Sema::AddArgumentDependentLookupCandidates(DeclarationName Name,
if (ExplicitTemplateArgs)
continue;

AddOverloadCandidate(FD, FoundDecl, Args, CandidateSet,
/*SuppressUserConversions=*/false, PartialOverloading,
/*AllowExplicit*/ true,
/*AllowExplicitConversions*/ false,
ADLCallKind::UsesADL);
AddOverloadCandidate(
FD, FoundDecl, Args, CandidateSet, /*SuppressUserConversions=*/false,
PartialOverloading, /*AllowExplicit=*/true,
/*AllowExplicitConversions=*/false, ADLCallKind::UsesADL);
if (CandidateSet.getRewriteInfo().shouldAddReversed(Context, FD)) {
AddOverloadCandidate(
FD, FoundDecl, {Args[1], Args[0]}, CandidateSet,
/*SuppressUserConversions=*/false, PartialOverloading,
/*AllowExplicit=*/true, /*AllowExplicitConversions=*/false,
ADLCallKind::UsesADL, None, OverloadCandidateParamOrder::Reversed);
}
} else {
auto *FTD = cast<FunctionTemplateDecl>(*I);
AddTemplateOverloadCandidate(
cast<FunctionTemplateDecl>(*I), FoundDecl, ExplicitTemplateArgs, Args,
CandidateSet,
FTD, FoundDecl, ExplicitTemplateArgs, Args, CandidateSet,
/*SuppressUserConversions=*/false, PartialOverloading,
/*AllowExplicit*/true, ADLCallKind::UsesADL);
/*AllowExplicit=*/true, ADLCallKind::UsesADL);
if (CandidateSet.getRewriteInfo().shouldAddReversed(
Context, FTD->getTemplatedDecl())) {
AddTemplateOverloadCandidate(
FTD, FoundDecl, ExplicitTemplateArgs, {Args[1], Args[0]},
CandidateSet, /*SuppressUserConversions=*/false, PartialOverloading,
/*AllowExplicit=*/true, ADLCallKind::UsesADL,
OverloadCandidateParamOrder::Reversed);
}
}
}
}
Expand Down
Expand Up @@ -122,7 +122,7 @@ namespace NoInjectionIfOperatorEqualsDeclared {
bool test_a = A() == A(); // expected-error {{invalid operands}}

struct B {
friend void operator==(int, struct Q); // expected-note {{not viable}}
friend void operator==(int, struct Q); // expected-note 2{{not viable}}
std::strong_ordering operator<=>(const B&) const = default;
};
bool test_b = B() == B(); // expected-error {{invalid operands}}
Expand Down
Expand Up @@ -113,6 +113,18 @@ namespace bullet4 {
X<3> reversed_add = x2 + x1; // expected-error {{invalid operands}}
}

namespace PR44627 {
namespace ADL {
struct type {};
bool operator==(type lhs, int rhs) {
return true;
}
}

bool b1 = ADL::type() == 0;
bool b2 = 0 == ADL::type();
}

// Various C++17 cases that are known to be broken by the C++20 rules.
namespace problem_cases {
// We can have an ambiguity between an operator and its reversed form. This
Expand Down

0 comments on commit 1db66e7

Please sign in to comment.