-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[clang] simplify constant template parameter type deduction for partial ordering #160433
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
@llvm/pr-subscribers-clang Author: Matheus Izvekov (mizvekov) ChangesThis simplifies things a little bit. This is mostly NFCish, except the reference type deduction workaround now applies in partial ordering as well, but we don't have any test cases and any reason to suspect this is significant. Full diff: https://github.com/llvm/llvm-project/pull/160433.diff 1 Files Affected:
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 62e867c44ad14..b0d2554d819cb 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -483,7 +483,7 @@ DeduceNonTypeTemplateArgument(Sema &S, TemplateParameterList *TemplateParams,
return TemplateDeductionResult::Inconsistent;
}
Deduced[NTTP.getIndex()] = Result;
- if (!S.getLangOpts().CPlusPlus17)
+ if (!S.getLangOpts().CPlusPlus17 && !PartialOrdering)
return TemplateDeductionResult::Success;
if (NTTP.isExpandedParameterPack())
@@ -2653,23 +2653,11 @@ DeduceTemplateArguments(Sema &S, TemplateParameterList *TemplateParams,
switch (A.getKind()) {
case TemplateArgument::Expression: {
const Expr *E = A.getAsExpr();
- // When checking NTTP, if either the parameter or the argument is
- // dependent, as there would be otherwise nothing to deduce, we force
- // the argument to the parameter type using this dependent implicit
- // cast, in order to maintain invariants. Now we can deduce the
- // resulting type from the original type, and deduce the original type
- // against the parameter we are checking.
- if (const auto *ICE = dyn_cast<ImplicitCastExpr>(E);
- ICE && ICE->getCastKind() == clang::CK_Dependent) {
+ // The type of the value is the type of the expression before any
+ // implicit conversions.
+ if (const auto *ICE = dyn_cast<ImplicitCastExpr>(E)) {
E = ICE->getSubExpr();
- if (auto Result = DeduceTemplateArgumentsByTypeMatch(
- S, TemplateParams, ICE->getType(), E->getType(), Info,
- Deduced, TDF_SkipNonDependent,
- PartialOrdering ? PartialOrderingKind::NonCall
- : PartialOrderingKind::None,
- /*DeducedFromArrayBound=*/false, HasDeducedAnyParam);
- Result != TemplateDeductionResult::Success)
- return Result;
+ assert(!isa<ImplicitCastExpr>(E));
}
return DeduceNonTypeTemplateArgument(
S, TemplateParams, NTTP, DeducedTemplateArgument(A), E->getType(),
|
…al ordering This simplifies things a little bit. This is mostly NFCish, except the reference type deduction workaround now applies in partial ordering as well, but we don't have any test cases and any reason to suspect this is significant.
09539af
to
d45e9e3
Compare
@erichkeane sorry to ping so soon, but this patch is quite small and its starting to form a deep stack of patches. |
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.
I'm not positive exactly what is the effect of this, but I'm willing to ship it for now and see.
…al ordering (llvm#160433) This simplifies things a little bit. This is mostly NFCish, except the reference type deduction workaround now applies in partial ordering as well, but we don't have any test cases and any reason to suspect this is significant.
This simplifies things a little bit. This is mostly NFCish, except the reference type deduction workaround now applies in partial ordering as well, but we don't have any test cases and any reason to suspect this is significant.