@@ -786,12 +786,16 @@ NonTypeTemplateParmDecl *NonTypeTemplateParmDecl::Create(
786
786
QualType T, bool ParameterPack, TypeSourceInfo *TInfo) {
787
787
AutoType *AT =
788
788
C.getLangOpts ().CPlusPlus20 ? T->getContainedAutoType () : nullptr ;
789
- return new (C, DC,
790
- additionalSizeToAlloc<std::pair<QualType, TypeSourceInfo *>,
791
- Expr *>(0 ,
792
- AT && AT->isConstrained () ? 1 : 0 ))
793
- NonTypeTemplateParmDecl (DC, StartLoc, IdLoc, D, P, Id, T, ParameterPack,
794
- TInfo);
789
+ bool const HasConstraint = AT && AT->isConstrained ();
790
+ auto *NTTP =
791
+ new (C, DC,
792
+ additionalSizeToAlloc<std::pair<QualType, TypeSourceInfo *>, Expr *>(
793
+ 0 , HasConstraint ? 1 : 0 ))
794
+ NonTypeTemplateParmDecl (DC, StartLoc, IdLoc, D, P, Id, T,
795
+ ParameterPack, TInfo);
796
+ if (HasConstraint)
797
+ NTTP->setPlaceholderTypeConstraint (nullptr );
798
+ return NTTP;
795
799
}
796
800
797
801
NonTypeTemplateParmDecl *NonTypeTemplateParmDecl::Create (
@@ -800,23 +804,30 @@ NonTypeTemplateParmDecl *NonTypeTemplateParmDecl::Create(
800
804
QualType T, TypeSourceInfo *TInfo, ArrayRef<QualType> ExpandedTypes,
801
805
ArrayRef<TypeSourceInfo *> ExpandedTInfos) {
802
806
AutoType *AT = TInfo->getType ()->getContainedAutoType ();
803
- return new (C, DC,
804
- additionalSizeToAlloc<std::pair<QualType, TypeSourceInfo *>,
805
- Expr *>(
806
- ExpandedTypes.size (), AT && AT->isConstrained () ? 1 : 0 ))
807
- NonTypeTemplateParmDecl (DC, StartLoc, IdLoc, D, P, Id, T, TInfo,
808
- ExpandedTypes, ExpandedTInfos);
807
+ bool const HasConstraint = AT && AT->isConstrained ();
808
+ auto *NTTP =
809
+ new (C, DC,
810
+ additionalSizeToAlloc<std::pair<QualType, TypeSourceInfo *>, Expr *>(
811
+ ExpandedTypes.size (), HasConstraint ? 1 : 0 ))
812
+ NonTypeTemplateParmDecl (DC, StartLoc, IdLoc, D, P, Id, T, TInfo,
813
+ ExpandedTypes, ExpandedTInfos);
814
+ if (HasConstraint)
815
+ NTTP->setPlaceholderTypeConstraint (nullptr );
816
+ return NTTP;
809
817
}
810
818
811
819
NonTypeTemplateParmDecl *
812
820
NonTypeTemplateParmDecl::CreateDeserialized (ASTContext &C, GlobalDeclID ID,
813
821
bool HasTypeConstraint) {
814
- return new (C, ID, additionalSizeToAlloc<std::pair<QualType,
815
- TypeSourceInfo *> ,
816
- Expr *>(0 ,
817
- HasTypeConstraint ? 1 : 0 ))
822
+ auto *NTTP =
823
+ new (C, ID ,
824
+ additionalSizeToAlloc<std::pair<QualType, TypeSourceInfo *>, Expr *>(
825
+ 0 , HasTypeConstraint ? 1 : 0 ))
818
826
NonTypeTemplateParmDecl (nullptr , SourceLocation (), SourceLocation (),
819
827
0 , 0 , nullptr , QualType (), false , nullptr );
828
+ if (HasTypeConstraint)
829
+ NTTP->setPlaceholderTypeConstraint (nullptr );
830
+ return NTTP;
820
831
}
821
832
822
833
NonTypeTemplateParmDecl *
@@ -830,6 +841,8 @@ NonTypeTemplateParmDecl::CreateDeserialized(ASTContext &C, GlobalDeclID ID,
830
841
NonTypeTemplateParmDecl (nullptr , SourceLocation (), SourceLocation (),
831
842
0 , 0 , nullptr , QualType (), nullptr , {}, {});
832
843
NTTP->NumExpandedTypes = NumExpandedTypes;
844
+ if (HasTypeConstraint)
845
+ NTTP->setPlaceholderTypeConstraint (nullptr );
833
846
return NTTP;
834
847
}
835
848
@@ -853,16 +866,6 @@ void NonTypeTemplateParmDecl::setDefaultArgument(
853
866
DefaultArgument.set (new (C) TemplateArgumentLoc (DefArg));
854
867
}
855
868
856
- void NonTypeTemplateParmDecl::setPlaceholderTypeConstraint (Expr *E) {
857
- assert (hasPlaceholderTypeConstraint () &&
858
- " setPlaceholderTypeConstraint called on a NonTypeTemplateParmDecl "
859
- " without constraint" );
860
- assert (!PlaceholderTypeConstraintInitialized && " PlaceholderTypeConstraint "
861
- " was already initialized!" );
862
- *getTrailingObjects<Expr *>() = E;
863
- PlaceholderTypeConstraintInitialized = true ;
864
- }
865
-
866
869
// ===----------------------------------------------------------------------===//
867
870
// TemplateTemplateParmDecl Method Implementations
868
871
// ===----------------------------------------------------------------------===//
0 commit comments