Skip to content

Commit 2ae72e1

Browse files
committed
Handle initializer in concept cache
1 parent db646e2 commit 2ae72e1

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

clang/lib/Sema/SemaConcept.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,11 @@ class HashParameterMapping : public RecursiveASTVisitor<HashParameterMapping> {
317317
}
318318

319319
bool TraverseDecl(Decl *D) {
320-
if (auto *VD = dyn_cast<ValueDecl>(D))
320+
if (auto *VD = dyn_cast<ValueDecl>(D)) {
321+
if (auto *Var = dyn_cast<VarDecl>(VD))
322+
TraverseStmt(Var->getInit());
321323
return TraverseType(VD->getType());
324+
}
322325

323326
return inherited::TraverseDecl(D);
324327
}
@@ -359,6 +362,10 @@ class HashParameterMapping : public RecursiveASTVisitor<HashParameterMapping> {
359362
return TraverseDecl(SOPE->getPack());
360363
}
361364

365+
bool VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E) {
366+
return inherited::TraverseStmt(E->getReplacement());
367+
}
368+
362369
void VisitConstraint(const NormalizedConstraintWithParamMapping &Constraint) {
363370
if (!Constraint.hasParameterMapping()) {
364371
for (const auto &List : TemplateArgs)

clang/test/SemaTemplate/concepts.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,4 +1361,47 @@ static_assert(true3<void>);
13611361

13621362
}
13631363

1364+
namespace case6 {
1365+
1366+
namespace std {
1367+
template <int __v>
1368+
struct integral_constant {
1369+
static const int value = __v;
1370+
};
1371+
1372+
template <class _Tp, class... _Args>
1373+
constexpr bool is_constructible_v = __is_constructible(_Tp, _Args...);
1374+
1375+
template <class _From, class _To>
1376+
constexpr bool is_convertible_v = __is_convertible(_From, _To);
1377+
1378+
template <class>
1379+
struct tuple_size;
1380+
1381+
template <class _Tp>
1382+
constexpr decltype(sizeof(int)) tuple_size_v = tuple_size<_Tp>::value;
1383+
} // namespace std
1384+
1385+
template <int N, int X>
1386+
concept FixedExtentConstructibleFromExtent = X == N;
1387+
1388+
template <int Extent>
1389+
struct span {
1390+
int static constexpr extent = Extent;
1391+
template <typename R, int N = std::tuple_size_v<R>>
1392+
requires(FixedExtentConstructibleFromExtent<extent, N>)
1393+
span(R);
1394+
};
1395+
1396+
template <class, int>
1397+
struct array {};
1398+
1399+
template <class _Tp, decltype(sizeof(int)) _Size>
1400+
struct std::tuple_size<array<_Tp, _Size>> : integral_constant<_Size> {};
1401+
1402+
static_assert(std::is_convertible_v<array<int, 3>, span<3>>);
1403+
static_assert(!std::is_constructible_v<span<4>, array<int, 3>>);
1404+
1405+
}
1406+
13641407
}

0 commit comments

Comments
 (0)