[clang] [clang] CTAD: Remove an incorrect assertion in BuildDeductionGuideForTypeAlias (PR #126532)

via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 11 00:10:03 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Haojian Wu (hokein)

<details>
<summary>Changes</summary>

Fixes #<!-- -->125821

The assertion was too strict, as Clang can reach this code path when recursively generating deduction guides for alias templates. See the detailed explanation [here](https://github.com/llvm/llvm-project/issues/125821#issuecomment-2639130893).

No release notes needed, as there is no behavior change in release builds.

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


2 Files Affected:

- (modified) clang/lib/Sema/SemaTemplateDeductionGuide.cpp (-2) 
- (modified) clang/test/SemaCXX/cxx20-ctad-type-alias.cpp (+14) 


``````````diff
diff --git a/clang/lib/Sema/SemaTemplateDeductionGuide.cpp b/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
index e5931f4684a57d..b789824d970208 100644
--- a/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
+++ b/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
@@ -998,8 +998,6 @@ getRHSTemplateDeclAndArgs(Sema &SemaRef, TypeAliasTemplateDecl *AliasTemplate) {
       Template = CTSD->getSpecializedTemplate();
       AliasRhsTemplateArgs = CTSD->getTemplateArgs().asArray();
     }
-  } else {
-    assert(false && "unhandled RHS type of the alias");
   }
   return {Template, AliasRhsTemplateArgs};
 }
diff --git a/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp b/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
index 37dca2215af6ba..832ce15e662508 100644
--- a/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
+++ b/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
@@ -525,3 +525,17 @@ template <ArrayType<int>::Array array> void test() {}
 void foo() { test<{1, 2, 3}>(); }
 
 } // namespace GH113518
+
+namespace GH125821 {
+template<typename T>
+struct A { A(T){} };
+
+template<typename T>
+using Proxy = T;
+
+template<typename T>
+using C = Proxy< A<T> >;
+
+C test{ 42 }; // expected-error {{no viable constructor or deduction guide for deduction of template arguments}}
+
+} // namespace GH125821

``````````

</details>


https://github.com/llvm/llvm-project/pull/126532


More information about the cfe-commits mailing list