[clang] [Sema] Default arguments for template parameters affect ContainsUnexpandedPacks (PR #99880)

Ilya Biryukov via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 23 10:13:02 PDT 2024


https://github.com/ilya-biryukov updated https://github.com/llvm/llvm-project/pull/99880

>From ad2d2f42282d5493761fa0af13b77dc7aab73bba Mon Sep 17 00:00:00 2001
From: Ilya Biryukov <ibiryukov at google.com>
Date: Mon, 22 Jul 2024 15:19:07 +0200
Subject: [PATCH 1/5] [Sema] Default arguments for template parameters affect
 ContainsUnexpandedPacks

This addresses the FIXME in the code. There are tests for the new
behavior in a follow up fix for #99877, which also addresses other bugs
that prevent exposing the wrong results of `ContainsUnexpandedPacks` in
the outputs of the compiler without crashes.
---
 clang/lib/AST/DeclTemplate.cpp | 38 ++++++++++++++++++++++++----------
 1 file changed, 27 insertions(+), 11 deletions(-)

diff --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp
index 722c7fcf0b0df..f95be88e6c087 100644
--- a/clang/lib/AST/DeclTemplate.cpp
+++ b/clang/lib/AST/DeclTemplate.cpp
@@ -61,27 +61,43 @@ TemplateParameterList::TemplateParameterList(const ASTContext& C,
 
     bool IsPack = P->isTemplateParameterPack();
     if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(P)) {
-      if (!IsPack && NTTP->getType()->containsUnexpandedParameterPack())
-        ContainsUnexpandedParameterPack = true;
+      if (!IsPack) {
+        if (NTTP->getType()->containsUnexpandedParameterPack())
+          ContainsUnexpandedParameterPack = true;
+        else if (NTTP->hasDefaultArgument() &&
+                 NTTP->getDefaultArgument()
+                     .getArgument()
+                     .containsUnexpandedParameterPack())
+          ContainsUnexpandedParameterPack = true;
+      }
       if (NTTP->hasPlaceholderTypeConstraint())
         HasConstrainedParameters = true;
     } else if (const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(P)) {
-      if (!IsPack &&
-          TTP->getTemplateParameters()->containsUnexpandedParameterPack())
-        ContainsUnexpandedParameterPack = true;
-    } else if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(P)) {
-      if (const TypeConstraint *TC = TTP->getTypeConstraint()) {
-        if (TC->getImmediatelyDeclaredConstraint()
-            ->containsUnexpandedParameterPack())
+      if (!IsPack) {
+        if (TTP->getTemplateParameters()->containsUnexpandedParameterPack())
           ContainsUnexpandedParameterPack = true;
+        else if (TTP->hasDefaultArgument() &&
+                 TTP->getDefaultArgument()
+                     .getArgument()
+                     .containsUnexpandedParameterPack())
+          ContainsUnexpandedParameterPack = true;
+      }
+    } else if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(P)) {
+      if (!IsPack && TTP->hasDefaultArgument() &&
+          TTP->getDefaultArgument()
+              .getArgument()
+              .containsUnexpandedParameterPack()) {
+        ContainsUnexpandedParameterPack = true;
+      } else if (const TypeConstraint *TC = TTP->getTypeConstraint();
+                 TC && TC->getImmediatelyDeclaredConstraint()
+                           ->containsUnexpandedParameterPack()) {
+        ContainsUnexpandedParameterPack = true;
       }
       if (TTP->hasTypeConstraint())
         HasConstrainedParameters = true;
     } else {
       llvm_unreachable("unexpected template parameter type");
     }
-    // FIXME: If a default argument contains an unexpanded parameter pack, the
-    // template parameter list does too.
   }
 
   if (HasRequiresClause) {

>From 34a18e0c78c2915df201aea368f6c2763f885fbe Mon Sep 17 00:00:00 2001
From: Ilya Biryukov <ibiryukov at google.com>
Date: Tue, 23 Jul 2024 13:01:10 +0200
Subject: [PATCH 2/5] fixup! [Sema] Default arguments for template parameters
 affect ContainsUnexpandedPacks

Add a helper function to avoid code duplication.
---
 clang/lib/AST/DeclTemplate.cpp | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp
index f95be88e6c087..5d207cfbecb97 100644
--- a/clang/lib/AST/DeclTemplate.cpp
+++ b/clang/lib/AST/DeclTemplate.cpp
@@ -45,6 +45,14 @@ using namespace clang;
 //===----------------------------------------------------------------------===//
 
 
+namespace {
+template<class TemplateParam>
+bool DefaultArgumentContainsUnexpandedPack(const TemplateParam& P) {
+  return P.hasDefaultArgument() &&
+         P.getDefaultArgument().getArgument().containsUnexpandedParameterPack();
+}
+}
+
 TemplateParameterList::TemplateParameterList(const ASTContext& C,
                                              SourceLocation TemplateLoc,
                                              SourceLocation LAngleLoc,
@@ -64,10 +72,7 @@ TemplateParameterList::TemplateParameterList(const ASTContext& C,
       if (!IsPack) {
         if (NTTP->getType()->containsUnexpandedParameterPack())
           ContainsUnexpandedParameterPack = true;
-        else if (NTTP->hasDefaultArgument() &&
-                 NTTP->getDefaultArgument()
-                     .getArgument()
-                     .containsUnexpandedParameterPack())
+        else if (DefaultArgumentContainsUnexpandedPack(*NTTP))
           ContainsUnexpandedParameterPack = true;
       }
       if (NTTP->hasPlaceholderTypeConstraint())
@@ -76,17 +81,11 @@ TemplateParameterList::TemplateParameterList(const ASTContext& C,
       if (!IsPack) {
         if (TTP->getTemplateParameters()->containsUnexpandedParameterPack())
           ContainsUnexpandedParameterPack = true;
-        else if (TTP->hasDefaultArgument() &&
-                 TTP->getDefaultArgument()
-                     .getArgument()
-                     .containsUnexpandedParameterPack())
+        else if (DefaultArgumentContainsUnexpandedPack(*TTP))
           ContainsUnexpandedParameterPack = true;
       }
     } else if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(P)) {
-      if (!IsPack && TTP->hasDefaultArgument() &&
-          TTP->getDefaultArgument()
-              .getArgument()
-              .containsUnexpandedParameterPack()) {
+      if (!IsPack && DefaultArgumentContainsUnexpandedPack(*TTP)) {
         ContainsUnexpandedParameterPack = true;
       } else if (const TypeConstraint *TC = TTP->getTypeConstraint();
                  TC && TC->getImmediatelyDeclaredConstraint()

>From d8e2db25421c459e6f2a19baf5e387ab377378ee Mon Sep 17 00:00:00 2001
From: Ilya Biryukov <ibiryukov at google.com>
Date: Tue, 23 Jul 2024 13:07:26 +0200
Subject: [PATCH 3/5] fixup! [Sema] Default arguments for template parameters
 affect ContainsUnexpandedPacks

reformat the code
---
 clang/lib/AST/DeclTemplate.cpp | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp
index 5d207cfbecb97..c1a4181d9b6e2 100644
--- a/clang/lib/AST/DeclTemplate.cpp
+++ b/clang/lib/AST/DeclTemplate.cpp
@@ -44,14 +44,13 @@ using namespace clang;
 // TemplateParameterList Implementation
 //===----------------------------------------------------------------------===//
 
-
 namespace {
-template<class TemplateParam>
-bool DefaultArgumentContainsUnexpandedPack(const TemplateParam& P) {
+template <class TemplateParam>
+bool DefaultArgumentContainsUnexpandedPack(const TemplateParam &P) {
   return P.hasDefaultArgument() &&
          P.getDefaultArgument().getArgument().containsUnexpandedParameterPack();
 }
-}
+} // namespace
 
 TemplateParameterList::TemplateParameterList(const ASTContext& C,
                                              SourceLocation TemplateLoc,

>From ae4021d31bf71622765221ac68b7ff1a316fe670 Mon Sep 17 00:00:00 2001
From: Ilya Biryukov <ibiryukov at google.com>
Date: Tue, 23 Jul 2024 15:51:04 +0200
Subject: [PATCH 4/5] fixup! [Sema] Default arguments for template parameters
 affect ContainsUnexpandedPacks

Simplify the code and reduce nesting
---
 clang/lib/AST/DeclTemplate.cpp | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp
index c1a4181d9b6e2..5a47b4e646355 100644
--- a/clang/lib/AST/DeclTemplate.cpp
+++ b/clang/lib/AST/DeclTemplate.cpp
@@ -68,20 +68,16 @@ TemplateParameterList::TemplateParameterList(const ASTContext& C,
 
     bool IsPack = P->isTemplateParameterPack();
     if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(P)) {
-      if (!IsPack) {
-        if (NTTP->getType()->containsUnexpandedParameterPack())
-          ContainsUnexpandedParameterPack = true;
-        else if (DefaultArgumentContainsUnexpandedPack(*NTTP))
-          ContainsUnexpandedParameterPack = true;
-      }
+      if (!IsPack && (NTTP->getType()->containsUnexpandedParameterPack() ||
+                      DefaultArgumentContainsUnexpandedPack(*NTTP)))
+        ContainsUnexpandedParameterPack = true;
       if (NTTP->hasPlaceholderTypeConstraint())
         HasConstrainedParameters = true;
     } else if (const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(P)) {
-      if (!IsPack) {
-        if (TTP->getTemplateParameters()->containsUnexpandedParameterPack())
-          ContainsUnexpandedParameterPack = true;
-        else if (DefaultArgumentContainsUnexpandedPack(*TTP))
-          ContainsUnexpandedParameterPack = true;
+      if (!IsPack &&
+          (TTP->getTemplateParameters()->containsUnexpandedParameterPack() ||
+           DefaultArgumentContainsUnexpandedPack(*TTP))) {
+        ContainsUnexpandedParameterPack = true;
       }
     } else if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(P)) {
       if (!IsPack && DefaultArgumentContainsUnexpandedPack(*TTP)) {

>From a3c6b242676ff01f8e067ade6edecbf0c064845b Mon Sep 17 00:00:00 2001
From: Ilya Biryukov <ibiryukov at google.com>
Date: Tue, 23 Jul 2024 19:11:46 +0200
Subject: [PATCH 5/5] fixup! [Sema] Default arguments for template parameters
 affect ContainsUnexpandedPacks

- Rename function
- Use static instead of anonymous namespace
---
 clang/lib/AST/DeclTemplate.cpp | 171 ++++++++++++++++-----------------
 1 file changed, 81 insertions(+), 90 deletions(-)

diff --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp
index 5a47b4e646355..32c0a05d6c34e 100644
--- a/clang/lib/AST/DeclTemplate.cpp
+++ b/clang/lib/AST/DeclTemplate.cpp
@@ -44,15 +44,14 @@ using namespace clang;
 // TemplateParameterList Implementation
 //===----------------------------------------------------------------------===//
 
-namespace {
 template <class TemplateParam>
-bool DefaultArgumentContainsUnexpandedPack(const TemplateParam &P) {
+static bool
+DefaultTemplateArgumentContainsUnexpandedPack(const TemplateParam &P) {
   return P.hasDefaultArgument() &&
          P.getDefaultArgument().getArgument().containsUnexpandedParameterPack();
 }
-} // namespace
 
-TemplateParameterList::TemplateParameterList(const ASTContext& C,
+TemplateParameterList::TemplateParameterList(const ASTContext &C,
                                              SourceLocation TemplateLoc,
                                              SourceLocation LAngleLoc,
                                              ArrayRef<NamedDecl *> Params,
@@ -69,18 +68,18 @@ TemplateParameterList::TemplateParameterList(const ASTContext& C,
     bool IsPack = P->isTemplateParameterPack();
     if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(P)) {
       if (!IsPack && (NTTP->getType()->containsUnexpandedParameterPack() ||
-                      DefaultArgumentContainsUnexpandedPack(*NTTP)))
+                      DefaultTemplateArgumentContainsUnexpandedPack(*NTTP)))
         ContainsUnexpandedParameterPack = true;
       if (NTTP->hasPlaceholderTypeConstraint())
         HasConstrainedParameters = true;
     } else if (const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(P)) {
       if (!IsPack &&
           (TTP->getTemplateParameters()->containsUnexpandedParameterPack() ||
-           DefaultArgumentContainsUnexpandedPack(*TTP))) {
+           DefaultTemplateArgumentContainsUnexpandedPack(*TTP))) {
         ContainsUnexpandedParameterPack = true;
       }
     } else if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(P)) {
-      if (!IsPack && DefaultArgumentContainsUnexpandedPack(*TTP)) {
+      if (!IsPack && DefaultTemplateArgumentContainsUnexpandedPack(*TTP)) {
         ContainsUnexpandedParameterPack = true;
       } else if (const TypeConstraint *TC = TTP->getTypeConstraint();
                  TC && TC->getImmediatelyDeclaredConstraint()
@@ -225,8 +224,8 @@ static bool AdoptTemplateParameterList(TemplateParameterList *Params,
   return Invalid;
 }
 
-void TemplateParameterList::
-getAssociatedConstraints(llvm::SmallVectorImpl<const Expr *> &AC) const {
+void TemplateParameterList::getAssociatedConstraints(
+    llvm::SmallVectorImpl<const Expr *> &AC) const {
   if (HasConstrainedParameters)
     for (const NamedDecl *Param : *this) {
       if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(Param)) {
@@ -261,7 +260,7 @@ bool TemplateParameterList::shouldIncludeTypeForArgument(
 namespace clang {
 
 void *allocateDefaultArgStorageChain(const ASTContext &C) {
-  return new (C) char[sizeof(void*) * 2];
+  return new (C) char[sizeof(void *) * 2];
 }
 
 } // namespace clang
@@ -277,8 +276,8 @@ TemplateDecl::TemplateDecl(Kind DK, DeclContext *DC, SourceLocation L,
 
 void TemplateDecl::anchor() {}
 
-void TemplateDecl::
-getAssociatedConstraints(llvm::SmallVectorImpl<const Expr *> &AC) const {
+void TemplateDecl::getAssociatedConstraints(
+    llvm::SmallVectorImpl<const Expr *> &AC) const {
   TemplateParams->getAssociatedConstraints(AC);
   if (auto *FD = dyn_cast_or_null<FunctionDecl>(getTemplatedDecl()))
     if (const Expr *TRC = FD->getTrailingRequiresClause())
@@ -309,7 +308,8 @@ bool TemplateDecl::isTypeAlias() const {
 
 void RedeclarableTemplateDecl::anchor() {}
 
-RedeclarableTemplateDecl::CommonBase *RedeclarableTemplateDecl::getCommonPtr() const {
+RedeclarableTemplateDecl::CommonBase *
+RedeclarableTemplateDecl::getCommonPtr() const {
   if (Common)
     return Common;
 
@@ -355,11 +355,11 @@ void RedeclarableTemplateDecl::loadLazySpecializationsImpl() const {
   }
 }
 
-template<class EntryType, typename... ProfileArguments>
+template <class EntryType, typename... ProfileArguments>
 typename RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::DeclType *
 RedeclarableTemplateDecl::findSpecializationImpl(
     llvm::FoldingSetVector<EntryType> &Specs, void *&InsertPos,
-    ProfileArguments&&... ProfileArgs) {
+    ProfileArguments &&...ProfileArgs) {
   using SETraits = SpecEntryTraits<EntryType>;
 
   llvm::FoldingSetNodeID ID;
@@ -369,7 +369,7 @@ RedeclarableTemplateDecl::findSpecializationImpl(
   return Entry ? SETraits::getDecl(Entry)->getMostRecentDecl() : nullptr;
 }
 
-template<class Derived, class EntryType>
+template <class Derived, class EntryType>
 void RedeclarableTemplateDecl::addSpecializationImpl(
     llvm::FoldingSetVector<EntryType> &Specializations, EntryType *Entry,
     void *InsertPos) {
@@ -378,8 +378,7 @@ void RedeclarableTemplateDecl::addSpecializationImpl(
   if (InsertPos) {
 #ifndef NDEBUG
     void *CorrectInsertPos;
-    assert(!findSpecializationImpl(Specializations,
-                                   CorrectInsertPos,
+    assert(!findSpecializationImpl(Specializations, CorrectInsertPos,
                                    SETraits::getTemplateArgs(Entry)) &&
            InsertPos == CorrectInsertPos &&
            "given incorrect InsertPos for specialization");
@@ -458,7 +457,7 @@ FunctionTemplateDecl::findSpecialization(ArrayRef<TemplateArgument> Args,
 }
 
 void FunctionTemplateDecl::addSpecialization(
-      FunctionTemplateSpecializationInfo *Info, void *InsertPos) {
+    FunctionTemplateSpecializationInfo *Info, void *InsertPos) {
   addSpecializationImpl<FunctionTemplateDecl>(getSpecializations(), Info,
                                               InsertPos);
 }
@@ -554,9 +553,9 @@ void ClassTemplateDecl::AddSpecialization(ClassTemplateSpecializationDecl *D,
 }
 
 ClassTemplatePartialSpecializationDecl *
-ClassTemplateDecl::findPartialSpecialization(
-    ArrayRef<TemplateArgument> Args,
-    TemplateParameterList *TPL, void *&InsertPos) {
+ClassTemplateDecl::findPartialSpecialization(ArrayRef<TemplateArgument> Args,
+                                             TemplateParameterList *TPL,
+                                             void *&InsertPos) {
   return findSpecializationImpl(getPartialSpecializations(), InsertPos, Args,
                                 TPL);
 }
@@ -571,13 +570,12 @@ void ClassTemplatePartialSpecializationDecl::Profile(
 }
 
 void ClassTemplateDecl::AddPartialSpecialization(
-                                      ClassTemplatePartialSpecializationDecl *D,
-                                      void *InsertPos) {
+    ClassTemplatePartialSpecializationDecl *D, void *InsertPos) {
   if (InsertPos)
     getPartialSpecializations().InsertNode(D, InsertPos);
   else {
-    ClassTemplatePartialSpecializationDecl *Existing
-      = getPartialSpecializations().GetOrInsertNode(D);
+    ClassTemplatePartialSpecializationDecl *Existing =
+        getPartialSpecializations().GetOrInsertNode(D);
     (void)Existing;
     assert(Existing->isCanonicalDecl() && "Non-canonical specialization?");
   }
@@ -588,8 +586,8 @@ void ClassTemplateDecl::AddPartialSpecialization(
 
 void ClassTemplateDecl::getPartialSpecializations(
     SmallVectorImpl<ClassTemplatePartialSpecializationDecl *> &PS) const {
-  llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> &PartialSpecs
-    = getPartialSpecializations();
+  llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> &PartialSpecs =
+      getPartialSpecializations();
   PS.clear();
   PS.reserve(PartialSpecs.size());
   for (ClassTemplatePartialSpecializationDecl &P : PartialSpecs)
@@ -610,9 +608,10 @@ ClassTemplateDecl::findPartialSpecialization(QualType T) {
 
 ClassTemplatePartialSpecializationDecl *
 ClassTemplateDecl::findPartialSpecInstantiatedFromMember(
-                                    ClassTemplatePartialSpecializationDecl *D) {
+    ClassTemplatePartialSpecializationDecl *D) {
   Decl *DCanon = D->getCanonicalDecl();
-  for (ClassTemplatePartialSpecializationDecl &P : getPartialSpecializations()) {
+  for (ClassTemplatePartialSpecializationDecl &P :
+       getPartialSpecializations()) {
     if (P.getInstantiatedFromMember()->getCanonicalDecl() == DCanon)
       return P.getMostRecentDecl();
   }
@@ -620,8 +619,7 @@ ClassTemplateDecl::findPartialSpecInstantiatedFromMember(
   return nullptr;
 }
 
-QualType
-ClassTemplateDecl::getInjectedClassNameSpecialization() {
+QualType ClassTemplateDecl::getInjectedClassNameSpecialization() {
   Common *CommonPtr = getCommonPtr();
   if (!CommonPtr->InjectedClassNameType.isNull())
     return CommonPtr->InjectedClassNameType;
@@ -653,11 +651,10 @@ TemplateTypeParmDecl *TemplateTypeParmDecl::Create(
     SourceLocation NameLoc, unsigned D, unsigned P, IdentifierInfo *Id,
     bool Typename, bool ParameterPack, bool HasTypeConstraint,
     std::optional<unsigned> NumExpanded) {
-  auto *TTPDecl =
-      new (C, DC,
-           additionalSizeToAlloc<TypeConstraint>(HasTypeConstraint ? 1 : 0))
-      TemplateTypeParmDecl(DC, KeyLoc, NameLoc, Id, Typename,
-                           HasTypeConstraint, NumExpanded);
+  auto *TTPDecl = new (
+      C, DC, additionalSizeToAlloc<TypeConstraint>(HasTypeConstraint ? 1 : 0))
+      TemplateTypeParmDecl(DC, KeyLoc, NameLoc, Id, Typename, HasTypeConstraint,
+                           NumExpanded);
   QualType TTPType = C.getTemplateTypeParmType(D, P, ParameterPack, TTPDecl);
   TTPDecl->setTypeForDecl(TTPType.getTypePtr());
   return TTPDecl;
@@ -755,10 +752,10 @@ NonTypeTemplateParmDecl *NonTypeTemplateParmDecl::Create(
     QualType T, bool ParameterPack, TypeSourceInfo *TInfo) {
   AutoType *AT =
       C.getLangOpts().CPlusPlus20 ? T->getContainedAutoType() : nullptr;
-  return new (C, DC,
-              additionalSizeToAlloc<std::pair<QualType, TypeSourceInfo *>,
-                                    Expr *>(0,
-                                            AT && AT->isConstrained() ? 1 : 0))
+  return new (
+      C, DC,
+      additionalSizeToAlloc<std::pair<QualType, TypeSourceInfo *>, Expr *>(
+          0, AT && AT->isConstrained() ? 1 : 0))
       NonTypeTemplateParmDecl(DC, StartLoc, IdLoc, D, P, Id, T, ParameterPack,
                               TInfo);
 }
@@ -769,10 +766,10 @@ NonTypeTemplateParmDecl *NonTypeTemplateParmDecl::Create(
     QualType T, TypeSourceInfo *TInfo, ArrayRef<QualType> ExpandedTypes,
     ArrayRef<TypeSourceInfo *> ExpandedTInfos) {
   AutoType *AT = TInfo->getType()->getContainedAutoType();
-  return new (C, DC,
-              additionalSizeToAlloc<std::pair<QualType, TypeSourceInfo *>,
-                                    Expr *>(
-                  ExpandedTypes.size(), AT && AT->isConstrained() ? 1 : 0))
+  return new (
+      C, DC,
+      additionalSizeToAlloc<std::pair<QualType, TypeSourceInfo *>, Expr *>(
+          ExpandedTypes.size(), AT && AT->isConstrained() ? 1 : 0))
       NonTypeTemplateParmDecl(DC, StartLoc, IdLoc, D, P, Id, T, TInfo,
                               ExpandedTypes, ExpandedTInfos);
 }
@@ -780,12 +777,12 @@ NonTypeTemplateParmDecl *NonTypeTemplateParmDecl::Create(
 NonTypeTemplateParmDecl *
 NonTypeTemplateParmDecl::CreateDeserialized(ASTContext &C, GlobalDeclID ID,
                                             bool HasTypeConstraint) {
-  return new (C, ID, additionalSizeToAlloc<std::pair<QualType,
-                                                     TypeSourceInfo *>,
-                                           Expr *>(0,
-                                                   HasTypeConstraint ? 1 : 0))
-          NonTypeTemplateParmDecl(nullptr, SourceLocation(), SourceLocation(),
-                                  0, 0, nullptr, QualType(), false, nullptr);
+  return new (
+      C, ID,
+      additionalSizeToAlloc<std::pair<QualType, TypeSourceInfo *>, Expr *>(
+          0, HasTypeConstraint ? 1 : 0))
+      NonTypeTemplateParmDecl(nullptr, SourceLocation(), SourceLocation(), 0, 0,
+                              nullptr, QualType(), false, nullptr);
 }
 
 NonTypeTemplateParmDecl *
@@ -914,8 +911,8 @@ FunctionTemplateSpecializationInfo *FunctionTemplateSpecializationInfo::Create(
     MemberSpecializationInfo *MSInfo) {
   const ASTTemplateArgumentListInfo *ArgsAsWritten = nullptr;
   if (TemplateArgsAsWritten)
-    ArgsAsWritten = ASTTemplateArgumentListInfo::Create(C,
-                                                        *TemplateArgsAsWritten);
+    ArgsAsWritten =
+        ASTTemplateArgumentListInfo::Create(C, *TemplateArgsAsWritten);
 
   void *Mem =
       C.Allocate(totalSizeToAlloc<MemberSpecializationInfo *>(MSInfo ? 1 : 0));
@@ -927,19 +924,16 @@ FunctionTemplateSpecializationInfo *FunctionTemplateSpecializationInfo::Create(
 // ClassTemplateSpecializationDecl Implementation
 //===----------------------------------------------------------------------===//
 
-ClassTemplateSpecializationDecl::
-ClassTemplateSpecializationDecl(ASTContext &Context, Kind DK, TagKind TK,
-                                DeclContext *DC, SourceLocation StartLoc,
-                                SourceLocation IdLoc,
-                                ClassTemplateDecl *SpecializedTemplate,
-                                ArrayRef<TemplateArgument> Args,
-                                ClassTemplateSpecializationDecl *PrevDecl)
+ClassTemplateSpecializationDecl::ClassTemplateSpecializationDecl(
+    ASTContext &Context, Kind DK, TagKind TK, DeclContext *DC,
+    SourceLocation StartLoc, SourceLocation IdLoc,
+    ClassTemplateDecl *SpecializedTemplate, ArrayRef<TemplateArgument> Args,
+    ClassTemplateSpecializationDecl *PrevDecl)
     : CXXRecordDecl(DK, TK, Context, DC, StartLoc, IdLoc,
                     SpecializedTemplate->getIdentifier(), PrevDecl),
-    SpecializedTemplate(SpecializedTemplate),
-    TemplateArgs(TemplateArgumentList::CreateCopy(Context, Args)),
-    SpecializationKind(TSK_Undeclared) {
-}
+      SpecializedTemplate(SpecializedTemplate),
+      TemplateArgs(TemplateArgumentList::CreateCopy(Context, Args)),
+      SpecializationKind(TSK_Undeclared) {}
 
 ClassTemplateSpecializationDecl::ClassTemplateSpecializationDecl(ASTContext &C,
                                                                  Kind DK)
@@ -947,18 +941,14 @@ ClassTemplateSpecializationDecl::ClassTemplateSpecializationDecl(ASTContext &C,
                     SourceLocation(), nullptr, nullptr),
       SpecializationKind(TSK_Undeclared) {}
 
-ClassTemplateSpecializationDecl *
-ClassTemplateSpecializationDecl::Create(ASTContext &Context, TagKind TK,
-                                        DeclContext *DC,
-                                        SourceLocation StartLoc,
-                                        SourceLocation IdLoc,
-                                        ClassTemplateDecl *SpecializedTemplate,
-                                        ArrayRef<TemplateArgument> Args,
-                                   ClassTemplateSpecializationDecl *PrevDecl) {
-  auto *Result =
-      new (Context, DC) ClassTemplateSpecializationDecl(
-          Context, ClassTemplateSpecialization, TK, DC, StartLoc, IdLoc,
-          SpecializedTemplate, Args, PrevDecl);
+ClassTemplateSpecializationDecl *ClassTemplateSpecializationDecl::Create(
+    ASTContext &Context, TagKind TK, DeclContext *DC, SourceLocation StartLoc,
+    SourceLocation IdLoc, ClassTemplateDecl *SpecializedTemplate,
+    ArrayRef<TemplateArgument> Args,
+    ClassTemplateSpecializationDecl *PrevDecl) {
+  auto *Result = new (Context, DC) ClassTemplateSpecializationDecl(
+      Context, ClassTemplateSpecialization, TK, DC, StartLoc, IdLoc,
+      SpecializedTemplate, Args, PrevDecl);
   Result->setMayHaveOutOfDateDef(false);
 
   // If the template decl is incomplete, copy the external lexical storage from
@@ -967,7 +957,7 @@ ClassTemplateSpecializationDecl::Create(ASTContext &Context, TagKind TK,
   // external AST.
   if (!SpecializedTemplate->getTemplatedDecl()->isCompleteDefinition())
     Result->setHasExternalLexicalStorage(
-      SpecializedTemplate->getTemplatedDecl()->hasExternalLexicalStorage());
+        SpecializedTemplate->getTemplatedDecl()->hasExternalLexicalStorage());
 
   Context.getTypeDeclType(Result, PrevDecl);
   return Result;
@@ -976,8 +966,8 @@ ClassTemplateSpecializationDecl::Create(ASTContext &Context, TagKind TK,
 ClassTemplateSpecializationDecl *
 ClassTemplateSpecializationDecl::CreateDeserialized(ASTContext &C,
                                                     GlobalDeclID ID) {
-  auto *Result =
-    new (C, ID) ClassTemplateSpecializationDecl(C, ClassTemplateSpecialization);
+  auto *Result = new (C, ID)
+      ClassTemplateSpecializationDecl(C, ClassTemplateSpecialization);
   Result->setMayHaveOutOfDateDef(false);
   return Result;
 }
@@ -1003,13 +993,12 @@ void ClassTemplateSpecializationDecl::getNameForDiagnostic(
 ClassTemplateDecl *
 ClassTemplateSpecializationDecl::getSpecializedTemplate() const {
   if (const auto *PartialSpec =
-          SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization*>())
+          SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>())
     return PartialSpec->PartialSpecialization->getSpecializedTemplate();
-  return SpecializedTemplate.get<ClassTemplateDecl*>();
+  return SpecializedTemplate.get<ClassTemplateDecl *>();
 }
 
-SourceRange
-ClassTemplateSpecializationDecl::getSourceRange() const {
+SourceRange ClassTemplateSpecializationDecl::getSourceRange() const {
   switch (getSpecializationKind()) {
   case TSK_Undeclared:
   case TSK_ImplicitInstantiation: {
@@ -1088,9 +1077,8 @@ ConceptDecl *ConceptDecl::Create(ASTContext &C, DeclContext *DC,
 }
 
 ConceptDecl *ConceptDecl::CreateDeserialized(ASTContext &C, GlobalDeclID ID) {
-  ConceptDecl *Result = new (C, ID) ConceptDecl(nullptr, SourceLocation(),
-                                                DeclarationName(),
-                                                nullptr, nullptr);
+  ConceptDecl *Result = new (C, ID) ConceptDecl(
+      nullptr, SourceLocation(), DeclarationName(), nullptr, nullptr);
 
   return Result;
 }
@@ -1308,7 +1296,8 @@ void VarTemplateDecl::AddSpecialization(VarTemplateSpecializationDecl *D,
 
 VarTemplatePartialSpecializationDecl *
 VarTemplateDecl::findPartialSpecialization(ArrayRef<TemplateArgument> Args,
-     TemplateParameterList *TPL, void *&InsertPos) {
+                                           TemplateParameterList *TPL,
+                                           void *&InsertPos) {
   return findSpecializationImpl(getPartialSpecializations(), InsertPos, Args,
                                 TPL);
 }
@@ -1609,8 +1598,9 @@ createTypePackElementParameterList(const ASTContext &C, DeclContext *DC) {
                                        nullptr);
 }
 
-static TemplateParameterList *createBuiltinTemplateParameterList(
-    const ASTContext &C, DeclContext *DC, BuiltinTemplateKind BTK) {
+static TemplateParameterList *
+createBuiltinTemplateParameterList(const ASTContext &C, DeclContext *DC,
+                                   BuiltinTemplateKind BTK) {
   switch (BTK) {
   case BTK__make_integer_seq:
     return createMakeIntegerSeqParameterList(C, DC);
@@ -1641,7 +1631,8 @@ TemplateParamObjectDecl *TemplateParamObjectDecl::Create(const ASTContext &C,
 
 TemplateParamObjectDecl *
 TemplateParamObjectDecl::CreateDeserialized(ASTContext &C, GlobalDeclID ID) {
-  auto *TPOD = new (C, ID) TemplateParamObjectDecl(nullptr, QualType(), APValue());
+  auto *TPOD =
+      new (C, ID) TemplateParamObjectDecl(nullptr, QualType(), APValue());
   C.addDestruction(&TPOD->Value);
   return TPOD;
 }



More information about the cfe-commits mailing list