[clang] 0e3ae35 - [Concepts] Profile TypeConstraints in ProfileTemplateParameterList

Saar Raz via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 22 23:49:55 PST 2020


Author: Saar Raz
Date: 2020-01-23T09:47:55+02:00
New Revision: 0e3ae353a47273825cd2f20f4777dcb5731cf8ec

URL: https://github.com/llvm/llvm-project/commit/0e3ae353a47273825cd2f20f4777dcb5731cf8ec
DIFF: https://github.com/llvm/llvm-project/commit/0e3ae353a47273825cd2f20f4777dcb5731cf8ec.diff

LOG: [Concepts] Profile TypeConstraints in ProfileTemplateParameterList

Profile TypeConstraints in ProfileTemplateParameterList so we can distinguish
between partial specializations which differ in their TemplateParameterList
type constraints

Added: 
    

Modified: 
    clang/lib/AST/DeclTemplate.cpp
    clang/test/CXX/temp/temp.constr/temp.constr.constr/partial-specializations.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp
index e750bb8b6af7..02296d8aea16 100755
--- a/clang/lib/AST/DeclTemplate.cpp
+++ b/clang/lib/AST/DeclTemplate.cpp
@@ -488,7 +488,15 @@ static void ProfileTemplateParameterList(ASTContext &C,
     if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(D)) {
       ID.AddInteger(1);
       ID.AddBoolean(TTP->isParameterPack());
-      // TODO: Concepts: profile type-constraints.
+      ID.AddBoolean(TTP->hasTypeConstraint());
+      if (const TypeConstraint *TC = TTP->getTypeConstraint()) {
+        ID.AddPointer(TC->getNamedConcept()->getCanonicalDecl());
+        ID.AddBoolean(TC->hasExplicitTemplateArgs());
+        if (TC->hasExplicitTemplateArgs()) {
+          for (const auto &Arg : TC->getTemplateArgsAsWritten()->arguments())
+            Arg.getArgument().Profile(ID, C);
+        }
+      }
       continue;
     }
     const auto *TTP = cast<TemplateTemplateParmDecl>(D);

diff  --git a/clang/test/CXX/temp/temp.constr/temp.constr.constr/partial-specializations.cpp b/clang/test/CXX/temp/temp.constr/temp.constr.constr/partial-specializations.cpp
index 1ea4da29ee9f..9f3c21f99174 100644
--- a/clang/test/CXX/temp/temp.constr/temp.constr.constr/partial-specializations.cpp
+++ b/clang/test/CXX/temp/temp.constr/temp.constr.constr/partial-specializations.cpp
@@ -31,6 +31,23 @@ namespace class_templates
   // expected-note at -2{{during template argument deduction for class template partial specialization 'B<T *>' [with T = int *]}}
   // expected-note at -3{{during template argument deduction for class template partial specialization 'B<T **>' [with T = int]}}
   // expected-note at -4 2{{in instantiation of template class 'class_templates::B<int **>' requested here}}
+
+  template<typename T, typename U = double>
+  concept same_as = is_same<T, U>::value;
+
+  template<same_as<bool> T> requires A<T>::type
+  struct B<T*> {};
+  // expected-note at -1{{previous}}
+
+  template<same_as<bool> T> requires A<T>::type
+  struct B<T*> {};
+  // expected-error at -1{{redefinition}}
+
+  template<same_as T> requires A<T>::type
+  struct B<T*> {};
+
+  template<same_as<int> T> requires A<T>::type
+  struct B<T*> {};
 }
 
 namespace variable_templates


        


More information about the cfe-commits mailing list