llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Younan Zhang (zyn0217)

<details>
<summary>Changes</summary>

The RHS could be a non-dependent type alias, and thus they are not always 
TemplateSpecializationType.

This addresses 
https://github.com/llvm/llvm-project/pull/147675#discussion_r4487870799

---
Full diff: https://github.com/llvm/llvm-project/pull/240754.diff


2 Files Affected:

- (modified) clang/lib/Sema/SemaTemplateDeductionGuide.cpp (+16-4) 
- (modified) clang/test/SemaCXX/cxx20-ctad-type-alias.cpp (+17) 


``````````diff
diff --git a/clang/lib/Sema/SemaTemplateDeductionGuide.cpp 
b/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
index fa0918ae30282b..ae69a7f8010c60 100644
--- a/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
+++ b/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
@@ -1196,10 +1196,22 @@ getRHSTemplateDeclAndArgs(Sema &SemaRef, 
TypeAliasTemplateDecl *AliasTemplate) {
     // Cases where the RHS of the alias is dependent. e.g.
     //   template<typename T>
     //   using AliasFoo1 = Foo<T>; // a class/type alias template 
specialization
-    Template = TST->getTemplateName().getAsTemplateDecl();
-    AliasRhsTemplateArgs =
-        TST->getAsNonAliasTemplateSpecializationType()->template_arguments();
-  } else if (const auto *RT = RhsType->getAs<RecordType>()) {
+
+    // Look through RHS until we find a non-alias template.
+    // This is basically Type::getAsNonAliasTemplateSpecializationType, but we
+    // don't assume RHS is always TemplateSpecializationType.
+    while (TST && TST->isTypeAlias()) {
+      RhsType = TST->desugar();
+      TST = RhsType->getAs<TemplateSpecializationType>();
+    }
+    if (TST) {
+      Template = TST->getTemplateName().getAsTemplateDecl();
+      AliasRhsTemplateArgs = TST->template_arguments();
+      return {Template, AliasRhsTemplateArgs};
+    }
+    // We continue here in case RHS is non-dependent now.
+  }
+  if (const auto *RT = RhsType->getAs<RecordType>()) {
     // Cases where template arguments in the RHS of the alias are not
     // dependent. e.g.
     //   using AliasFoo = Foo<bool>;
diff --git a/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp 
b/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
index 78911cbaed67be..fa4f74e1e8cdbb 100644
--- a/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
+++ b/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
@@ -629,3 +629,20 @@ template <typename T> using S3 = S2<T>; // expected-note 
{{candidate function no
                                         // expected-note {{cannot deduce 
template arguments for 'GH190517::S3' from 'GH190517::S1<char>'}}
 S3 foo(42); // expected-error {{no viable constructor or deduction guide for 
deduction of template arguments of 'S3'}}
 }
+
+namespace post_GH147675 {
+
+template<class T> struct Foo { using self = Foo; Foo(T); };
+
+template<class> using Int = typename Foo<int>::self;
+
+template<class T> using A = Int<T>; // #post_GH147675_A
+
+A a = 1;
+
+A b = nullptr;
+// expected-error@-1 {{no viable constructor or deduction guide}}
+// expected-note@#post_GH147675_A 2{{candidate function}}
+// expected-note@#post_GH147675_A 2{{implicit deduction guide}}
+
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/240754
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to