Skip to content

Commit 0e3ae35

Browse files
committed
[Concepts] Profile TypeConstraints in ProfileTemplateParameterList
Profile TypeConstraints in ProfileTemplateParameterList so we can distinguish between partial specializations which differ in their TemplateParameterList type constraints
1 parent 1db1b8b commit 0e3ae35

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

clang/lib/AST/DeclTemplate.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,15 @@ static void ProfileTemplateParameterList(ASTContext &C,
488488
if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(D)) {
489489
ID.AddInteger(1);
490490
ID.AddBoolean(TTP->isParameterPack());
491-
// TODO: Concepts: profile type-constraints.
491+
ID.AddBoolean(TTP->hasTypeConstraint());
492+
if (const TypeConstraint *TC = TTP->getTypeConstraint()) {
493+
ID.AddPointer(TC->getNamedConcept()->getCanonicalDecl());
494+
ID.AddBoolean(TC->hasExplicitTemplateArgs());
495+
if (TC->hasExplicitTemplateArgs()) {
496+
for (const auto &Arg : TC->getTemplateArgsAsWritten()->arguments())
497+
Arg.getArgument().Profile(ID, C);
498+
}
499+
}
492500
continue;
493501
}
494502
const auto *TTP = cast<TemplateTemplateParmDecl>(D);

clang/test/CXX/temp/temp.constr/temp.constr.constr/partial-specializations.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,23 @@ namespace class_templates
3131
// expected-note@-2{{during template argument deduction for class template partial specialization 'B<T *>' [with T = int *]}}
3232
// expected-note@-3{{during template argument deduction for class template partial specialization 'B<T **>' [with T = int]}}
3333
// expected-note@-4 2{{in instantiation of template class 'class_templates::B<int **>' requested here}}
34+
35+
template<typename T, typename U = double>
36+
concept same_as = is_same<T, U>::value;
37+
38+
template<same_as<bool> T> requires A<T>::type
39+
struct B<T*> {};
40+
// expected-note@-1{{previous}}
41+
42+
template<same_as<bool> T> requires A<T>::type
43+
struct B<T*> {};
44+
// expected-error@-1{{redefinition}}
45+
46+
template<same_as T> requires A<T>::type
47+
struct B<T*> {};
48+
49+
template<same_as<int> T> requires A<T>::type
50+
struct B<T*> {};
3451
}
3552

3653
namespace variable_templates

0 commit comments

Comments
 (0)