@@ -786,12 +786,16 @@ NonTypeTemplateParmDecl *NonTypeTemplateParmDecl::Create(
786786 QualType T, bool ParameterPack, TypeSourceInfo *TInfo) {
787787 AutoType *AT =
788788 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;
795799}
796800
797801NonTypeTemplateParmDecl *NonTypeTemplateParmDecl::Create (
@@ -800,23 +804,30 @@ NonTypeTemplateParmDecl *NonTypeTemplateParmDecl::Create(
800804 QualType T, TypeSourceInfo *TInfo, ArrayRef<QualType> ExpandedTypes,
801805 ArrayRef<TypeSourceInfo *> ExpandedTInfos) {
802806 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;
809817}
810818
811819NonTypeTemplateParmDecl *
812820NonTypeTemplateParmDecl::CreateDeserialized (ASTContext &C, GlobalDeclID ID,
813821 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 ))
818826 NonTypeTemplateParmDecl (nullptr , SourceLocation (), SourceLocation (),
819827 0 , 0 , nullptr , QualType (), false , nullptr );
828+ if (HasTypeConstraint)
829+ NTTP->setPlaceholderTypeConstraint (nullptr );
830+ return NTTP;
820831}
821832
822833NonTypeTemplateParmDecl *
@@ -830,6 +841,8 @@ NonTypeTemplateParmDecl::CreateDeserialized(ASTContext &C, GlobalDeclID ID,
830841 NonTypeTemplateParmDecl (nullptr , SourceLocation (), SourceLocation (),
831842 0 , 0 , nullptr , QualType (), nullptr , {}, {});
832843 NTTP->NumExpandedTypes = NumExpandedTypes;
844+ if (HasTypeConstraint)
845+ NTTP->setPlaceholderTypeConstraint (nullptr );
833846 return NTTP;
834847}
835848
@@ -853,16 +866,6 @@ void NonTypeTemplateParmDecl::setDefaultArgument(
853866 DefaultArgument.set (new (C) TemplateArgumentLoc (DefArg));
854867}
855868
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-
866869// ===----------------------------------------------------------------------===//
867870// TemplateTemplateParmDecl Method Implementations
868871// ===----------------------------------------------------------------------===//
0 commit comments