[clang] [Clang] Fix various bugs in alias CTAD transform (PR #132061)

Younan Zhang via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 21 07:45:15 PDT 2025


================
@@ -1072,12 +1072,25 @@ BuildDeductionGuideForTypeAlias(Sema &SemaRef,
       AliasRhsTemplateArgs, TDeduceInfo, DeduceResults,
       /*NumberOfArgumentsMustMatch=*/false);
 
+  static auto IsNonDeducedArgument = [&](const DeducedTemplateArgument &TA) {
+    // The following cases indicate the template argument is non-deducible:
+    //   1. The result is null. E.g. When it comes from a default template
+    //   argument that doesn't appear in the alias declaration.
+    //   2. The template parameter is a pack and that cannot be deduced from
+    //   the arguments within the alias declaration.
+    // Non-deducible template parameters will persist in the transformed
+    // deduction guide.
+    return TA.isNull() || (TA.getKind() == TemplateArgument::Pack &&
+                           TA.pack_size() == 1 && TA.pack_begin()->isNull());
----------------
zyn0217 wrote:

(Oh silly me I thought I have asked myself the same question but I quickly forgot to get to it again...)

Yes you're right, we should traverse each element of the pack. I added a test case to reflect that: https://github.com/llvm/llvm-project/pull/132061/commits/74e4444c072d116b48147ba06fd45db57fbbcc03

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


More information about the cfe-commits mailing list