Skip to content

Commit d42d5eb

Browse files
committed
[Concepts] Implement P1616R1 - Using unconstrained template template parameters with constrained templates
Summary: Allow unconstrained template template parameters to accept constrainted templates as arguments. Reviewers: rsmith Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D73155
1 parent c77bbea commit d42d5eb

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7164,6 +7164,11 @@ bool Sema::CheckTemplateTemplateArgument(TemplateTemplateParmDecl *Param,
71647164
// [temp.constr.order].
71657165
SmallVector<const Expr *, 3> ParamsAC, TemplateAC;
71667166
Params->getAssociatedConstraints(ParamsAC);
7167+
// C++2a[temp.arg.template]p3
7168+
// [...] In this comparison, if P is unconstrained, the constraints on A
7169+
// are not considered.
7170+
if (ParamsAC.empty())
7171+
return false;
71677172
Template->getAssociatedConstraints(TemplateAC);
71687173
bool IsParamAtLeastAsConstrained;
71697174
if (IsAtLeastAsConstrained(Param, ParamsAC, Template, TemplateAC,

clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ template<typename T> concept F = T::f();
77
// expected-note@-1{{similar constraint expressions not considered equivalent}}
88
template<template<C> class P> struct S1 { }; // expected-note 2{{'P' declared here}}
99

10-
template<C> struct X { }; // expected-note{{'X' declared here}}
10+
template<C> struct X { };
1111

12-
template<D> struct Y { }; // expected-note 2{{'Y' declared here}}
12+
template<D> struct Y { }; // expected-note{{'Y' declared here}}
1313
template<typename T> struct Z { };
1414
template<F> struct W { }; // expected-note{{'W' declared here}}
1515

@@ -18,10 +18,10 @@ S1<Y> s12; // expected-error{{template template argument 'Y' is more constrained
1818
S1<Z> s13;
1919
S1<W> s14; // expected-error{{template template argument 'W' is more constrained than template template parameter 'P'}}
2020

21-
template<template<typename> class P> struct S2 { }; // expected-note 2{{'P' declared here}}
21+
template<template<typename> class P> struct S2 { };
2222

23-
S2<X> s21; // expected-error{{template template argument 'X' is more constrained than template template parameter 'P'}}
24-
S2<Y> s22; // expected-error{{template template argument 'Y' is more constrained than template template parameter 'P'}}
23+
S2<X> s21;
24+
S2<Y> s22;
2525
S2<Z> s23;
2626

2727
template <template <typename...> class C>

0 commit comments

Comments
 (0)