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

via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 13 03:15:28 PST 2025


Author: Haojian Wu
Date: 2025-02-13T12:15:24+01:00
New Revision: b963d3768c0e88d2cac043d4754ce90a19a7e1ec

URL: https://github.com/llvm/llvm-project/commit/b963d3768c0e88d2cac043d4754ce90a19a7e1ec
DIFF: https://github.com/llvm/llvm-project/commit/b963d3768c0e88d2cac043d4754ce90a19a7e1ec.diff

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

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.

Added: 
    

Modified: 
    clang/lib/Sema/SemaTemplateDeductionGuide.cpp
    clang/test/SemaCXX/cxx20-ctad-type-alias.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaTemplateDeductionGuide.cpp b/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
index e5931f4684a57..b789824d97020 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 37dca2215af6b..832ce15e66250 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


        


More information about the cfe-commits mailing list