[clang] [Clang] Fix an integer overflow issue in computing CTAD's parameter depth (PR #128704)

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 25 07:43:02 PST 2025


================
@@ -377,8 +377,12 @@ struct ConvertConstructorToDeductionGuideTransform {
         if (NestedPattern)
           Args.addOuterRetainedLevels(NestedPattern->getTemplateDepth());
         auto [Depth, Index] = getDepthAndIndex(Param);
+        assert(Depth ||
+               cast<ClassTemplateSpecializationDecl>(FTD->getDeclContext())
+                   ->isExplicitSpecialization());
         NamedDecl *NewParam = transformTemplateParameter(
-            SemaRef, DC, Param, Args, Index + Depth1IndexAdjustment, Depth - 1);
+            SemaRef, DC, Param, Args, Index + Depth1IndexAdjustment,
+            Depth ? Depth - 1 : 0);
----------------
hokein wrote:

> So I think that, in the end the depth should always be 0. But I'm happy to use Depth instead of a literal 0 if that seems more appropriate.

I agree, this seems like always the case, `Depth` for the new transformed template parameter is `0`.

I think we need some comments for the special `0` case.

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


More information about the cfe-commits mailing list