-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Clang] Fix the assertion condition after b8d1f3d6 #132669
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: Younan Zhang (zyn0217) ChangesThanks to the example provided by @MagentaTreehouse, I realized the assertion I added didn't cover all valid cases like, when inheriting from a class template specialization, the source of a synthesized template parameter might be an implicit specialization, whose inner function template is thus living at depth 0, for which we don’t want it to overflow too. Full diff: https://github.com/llvm/llvm-project/pull/132669.diff 2 Files Affected:
diff --git a/clang/lib/Sema/SemaTemplateDeductionGuide.cpp b/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
index 9cfdb7596b660..e20130a33f368 100644
--- a/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
+++ b/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
@@ -376,12 +376,14 @@ struct ConvertConstructorToDeductionGuideTransform {
if (NestedPattern)
Args.addOuterRetainedLevels(NestedPattern->getTemplateDepth());
auto [Depth, Index] = getDepthAndIndex(Param);
- // Depth can still be 0 if FTD belongs to an explicit class template
- // specialization with an empty template parameter list. In that case,
- // we don't want the NewDepth to overflow, and it should remain 0.
+ // Depth can be 0 if FTD belongs to a class template specialization with
+ // an empty template parameter list (i.e. either an explicit full
+ // specialization or an implicit specialization) In that case, we don't
+ // want the NewDepth to overflow, and it should remain 0.
assert(Depth ||
- cast<ClassTemplateSpecializationDecl>(FTD->getDeclContext())
- ->isExplicitSpecialization());
+ isa<ClassTemplateDecl *>(
+ cast<ClassTemplateSpecializationDecl>(FTD->getDeclContext())
+ ->getSpecializedTemplateOrPartial()));
NamedDecl *NewParam = transformTemplateParameter(
SemaRef, DC, Param, Args, Index + Depth1IndexAdjustment,
Depth ? Depth - 1 : 0);
diff --git a/clang/test/SemaTemplate/deduction-guide.cpp b/clang/test/SemaTemplate/deduction-guide.cpp
index ecd152abebd74..95e740a026550 100644
--- a/clang/test/SemaTemplate/deduction-guide.cpp
+++ b/clang/test/SemaTemplate/deduction-guide.cpp
@@ -723,3 +723,29 @@ void test() { NewDeleteAllocator abc(42); } // expected-error {{no viable constr
// CHECK-NEXT: `-ParmVarDecl {{.+}} 'T'
} // namespace GH128691
+
+namespace GH132616_DeductionGuide {
+
+template <class T> struct A {
+ template <class U>
+ A(U);
+};
+
+template <typename>
+struct B: A<int> {
+ using A::A;
+};
+
+template <class T>
+B(T) -> B<T>;
+
+B b(24);
+
+// CHECK-LABEL: Dumping GH132616_DeductionGuide::<deduction guide for B>:
+// CHECK-NEXT: FunctionTemplateDecl {{.+}} implicit <deduction guide for B>
+// CHECK-NEXT: |-TemplateTypeParmDecl {{.+}} typename depth 0 index 0
+// CHECK-NEXT: |-TemplateTypeParmDecl {{.+}} class depth 0 index 1 U
+// CHECK-NEXT: `-CXXDeductionGuideDecl {{.+}} implicit <deduction guide for B> 'auto (U) -> B<type-parameter-0-0>'
+// CHECK-NEXT: `-ParmVarDecl {{.+}} 'U'
+
+} // namespace GH132616_DeductionGuide
|
8562b2b
to
49f2a7e
Compare
Thanks to the example provided by @MagentaTreehouse, I realized the assertion I added didn't cover all valid cases like, when inheriting from a class template specialization, the source of a synthesized template parameter might be an implicit specialization, whose inner function template is thus living at depth 0, for which we don’t want it to overflow too.
49f2a7e
to
b7bef60
Compare
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/59/builds/14818 Here is the relevant piece of the build log for the reference
|
Thanks to the example provided by @MagentaTreehouse, I realized the assertion I added in b8d1f3d didn't cover all valid cases like, when inheriting from a class template specialization, the source of a synthesized template parameter might be an implicit specialization, whose inner function template is thus living at depth 0, for which we don’t want it to overflow too.
I've decided to remove that assertion because I don't think it's particularly useful: we're checking whether Depth = 0 parameters come from function templates whose parents contribute no template parameters to the depth, which is redundant given what the template depth already means.
This also incorporates a drive-by fix for #132061 (comment), which I somehow missed.