[Clang] Fix an integer overflow issue in computing CTAD's parameter d… · llvm/llvm-project@63e63f3 (original) (raw)

`@@ -377,8 +377,15 @@ struct ConvertConstructorToDeductionGuideTransform {

`

377

377

`if (NestedPattern)

`

378

378

` Args.addOuterRetainedLevels(NestedPattern->getTemplateDepth());

`

379

379

`auto [Depth, Index] = getDepthAndIndex(Param);

`

``

380

`+

// Depth can still be 0 if FTD belongs to an explicit class template

`

``

381

`+

// specialization with an empty template parameter list. In that case,

`

``

382

`+

// we don't want the NewDepth to overflow, and it should remain 0.

`

``

383

`+

assert(Depth ||

`

``

384

`+

cast(FTD->getDeclContext())

`

``

385

`+

->isExplicitSpecialization());

`

380

386

` NamedDecl *NewParam = transformTemplateParameter(

`

381

``

`-

SemaRef, DC, Param, Args, Index + Depth1IndexAdjustment, Depth - 1);

`

``

387

`+

SemaRef, DC, Param, Args, Index + Depth1IndexAdjustment,

`

``

388

`+

Depth ? Depth - 1 : 0);

`

382

389

`if (!NewParam)

`

383

390

`return nullptr;

`

384

391

`// Constraints require that we substitute depth-1 arguments

`