Skip to content

Commit 62c221b

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. Recommit, now profiling the IDC so that we can deal with situations where the TemplateArgsAsWritten are nullptr (happens when canonicalizing type constraints).
1 parent c985e7b commit 62c221b

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

clang/lib/AST/DeclTemplate.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,10 @@ 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+
TC->getImmediatelyDeclaredConstraint()->Profile(ID, C,
494+
/*Canonical=*/true);
492495
continue;
493496
}
494497
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)