-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[Clang] Bypass TAD during overload resolution if a perfect match exists #136018
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…match exists This implements the same overload resolution behavior as GCC, as described in https://wg21.link/p3606 (section 1-2, not 3) If during overload resolution, there is a non-template candidate that would be always be picked - because each of the argument is a perfect match (ie the source and target types are the same), we do not perform deduction for any template candidate that might exists. The goal is to be able to merge llvm#122423 without being too disruptive. This change means that the selection of the best viable candidate and template argument deduction become interleaved. To avoid rewriting half of Clang we store in `OverloadCandidateSet` enough information to be able to deduce template candidates from `OverloadCandidateSet::BestViableFunction`. Which means the lifetime of any object used by template argument must outlive a call to `Add*Template*Candidate`. This two phase resolution is not performed for some initialization as there are cases where template candidate are better match in these cases per the standard. It's also bypassed for code completion. The change has a nice impact on compile times https://llvm-compile-time-tracker.com/compare.php?from=719b029c16eeb1035da522fd641dfcc4cee6be74&to=bf7041045c9408490c395230047c5461de72fc39&stat=instructions%3Au Fixes llvm#62096 Fixes llvm#74581
… include a conversion
…tion in non-member calls
* Prefer a constructor template over a non-template conversion function
- We find a template conversion candidate - A constructor with a dependent explicit specifier
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 suggestion, 1 question.
clang/include/clang/Sema/Overload.h
Outdated
@@ -1005,14 +1005,14 @@ class Sema; | |||
|
|||
// An overload is a perfect match if the conversion | |||
// sequences for each argument are perfect. | |||
bool isPerfectMatch(const ASTContext &Ctx) const { | |||
bool isPerfectMatch(const ASTContext &Ctx, bool ForConversion) const { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Vastly prefer this take the Kind
, then line 1015 describe why conversions are ok when CSK_InitByUserDefinedConversion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed elsewhere, but in a touch of "lets leave it better than we found it", can we make an assert(HasFinalConversion)
everywhere else we access FinalConversion
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Accepted once you get the asserts requested.
clang/lib/Sema/SemaOverload.cpp
Outdated
@@ -5175,6 +5178,7 @@ FindConversionForRefInit(Sema &S, ImplicitConversionSequence &ICS, | |||
if (!Best->FinalConversion.DirectBinding) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about this 'if' here? Assert probably needs to be above this.
clang/docs/ReleaseNotes.rst
Outdated
@@ -96,6 +96,12 @@ C++ Language Changes | |||
asm((std::string_view("nop")) ::: (std::string_view("memory"))); | |||
} | |||
|
|||
- Clang now implements the changes to overload resolution proposed by section 1 and 2 of | |||
`P3606 <https://wg21.link/P3606R0>`_. If a non-template candidate exists in an overload set that is | |||
a perfect match (all conversion sequences are identity conversions) template candiates are not instantiated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a perfect match (all conversion sequences are identity conversions) template candiates are not instantiated. | |
a perfect match (all conversion sequences are identity conversions) template candidates are not instantiated. |
…tch exists" (#136113) Reverts #136018 Still some bots failing https://lab.llvm.org/buildbot/#/builders/52/builds/7643
… perfect match exists" (#136113) Reverts llvm/llvm-project#136018 Still some bots failing https://lab.llvm.org/buildbot/#/builders/52/builds/7643
…ts (llvm#136018) This implements the same overload resolution behavior as GCC, as described in https://wg21.link/p3606 (section 1-2, not 3) If during overload resolution, there is a non-template candidate that would be always be picked - because each of the argument is a perfect match (ie the source and target types are the same), we do not perform deduction for any template candidate that might exists. The goal is to be able to merge llvm#122423 without being too disruptive. This change means that the selection of the best viable candidate and template argument deduction become interleaved. To avoid rewriting half of Clang we store in `OverloadCandidateSet` enough information to be able to deduce template candidates from `OverloadCandidateSet::BestViableFunction`. Which means the lifetime of any object used by template argument must outlive a call to `Add*Template*Candidate`. This two phase resolution is not performed for some initialization as there are cases where template candidate are better match in these cases per the standard. It's also bypassed for code completion. The change has a nice impact on compile times https://llvm-compile-time-tracker.com/compare.php?from=719b029c16eeb1035da522fd641dfcc4cee6be74&to=bf7041045c9408490c395230047c5461de72fc39&stat=instructions%3Au Fixes llvm#62096 Fixes llvm#74581 Reapplies llvm#133426
…tch exists" (llvm#136113) Reverts llvm#136018 Still some bots failing https://lab.llvm.org/buildbot/#/builders/52/builds/7643
clang now fails an assertion on this
|
This implements the same overload resolution behavior as GCC,
as described in https://wg21.link/p3606 (section 1-2, not 3)
If during overload resolution, there is a non-template candidate
that would be always be picked - because each of the argument
is a perfect match (ie the source and target types are the same),
we do not perform deduction for any template candidate
that might exists.
The goal is to be able to merge #122423 without being too disruptive.
This change means that the selection of the best viable candidate and
template argument deduction become interleaved.
To avoid rewriting half of Clang we store in
OverloadCandidateSet
enough information to be able to deduce template candidates from
OverloadCandidateSet::BestViableFunction
. Which meansthe lifetime of any object used by template argument must outlive
a call to
Add*Template*Candidate
.This two phase resolution is not performed for some initialization
as there are cases where template candidate are better match
in these cases per the standard. It's also bypassed for code completion.
The change has a nice impact on compile times
https://llvm-compile-time-tracker.com/compare.php?from=719b029c16eeb1035da522fd641dfcc4cee6be74&to=bf7041045c9408490c395230047c5461de72fc39&stat=instructions%3Au
Fixes #62096
Fixes #74581
Reapplies #133426