Skip to content

Commit 2cb3e54

Browse files
committed
Additional tests
1 parent 144f3c9 commit 2cb3e54

File tree

2 files changed

+55
-8
lines changed

2 files changed

+55
-8
lines changed

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,9 +1530,19 @@ NamedDecl *Sema::ActOnNonTypeTemplateParameter(Scope *S, Declarator &D,
15301530
Param->setAccess(AS_public);
15311531

15321532
if (AutoTypeLoc TL = TInfo->getTypeLoc().getContainedAutoTypeLoc())
1533-
if (TL.isConstrained())
1534-
if (AttachTypeConstraint(TL, Param, Param, D.getEllipsisLoc()))
1533+
if (TL.isConstrained()) {
1534+
if (D.getEllipsisLoc().isInvalid() &&
1535+
T->containsUnexpandedParameterPack()) {
1536+
assert(TL.getConceptReference()->getTemplateArgsAsWritten());
1537+
for (auto &Loc :
1538+
TL.getConceptReference()->getTemplateArgsAsWritten()->arguments())
1539+
Invalid |= DiagnoseUnexpandedParameterPack(
1540+
Loc, UnexpandedParameterPackContext::UPPC_TypeConstraint);
1541+
}
1542+
if (!Invalid &&
1543+
AttachTypeConstraint(TL, Param, Param, D.getEllipsisLoc()))
15351544
Invalid = true;
1545+
}
15361546

15371547
if (Invalid)
15381548
Param->setInvalidDecl();

clang/test/SemaCXX/cxx2c-fold-exprs.cpp

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -313,24 +313,26 @@ template <typename...Ts> struct index_by;
313313
template <typename T, typename Indices>
314314
concept InitFunc = true;
315315

316-
namespace Invalid {
316+
namespace ExpandsBoth {
317317

318318
template <typename Indices, InitFunc<Indices> auto... init>
319-
struct LazyLitMatrix;
319+
struct LazyLitMatrix; // expected-note {{here}}
320320

321321
template <
322322
typename...Indices,
323323
InitFunc<index_by<Indices>> auto... init
324-
// expected-error@-1 {{type constraint contains unexpanded parameter pack 'Indices'}}
325324
>
326325
struct LazyLitMatrix<index_by<Indices...>, init...> {
327326
};
328327

329-
using T = LazyLitMatrix<index_by<int, char>, 42, 43>;
328+
// FIXME: Explain why we didn't pick up the partial specialization - pack sizes don't match.
329+
template struct LazyLitMatrix<index_by<int, char>, 42>;
330+
// expected-error@-1 {{instantiation of undefined template}}
331+
template struct LazyLitMatrix<index_by<int, char>, 42, 43>;
330332

331333
}
332334

333-
namespace Valid {
335+
namespace ExpandsRespectively {
334336

335337
template <typename Indices, InitFunc<Indices> auto... init>
336338
struct LazyLitMatrix;
@@ -342,7 +344,42 @@ template <
342344
struct LazyLitMatrix<index_by<Indices...>, init...> {
343345
};
344346

345-
using T = LazyLitMatrix<index_by<int, char>, 42, 43>;
347+
template struct LazyLitMatrix<index_by<int, char>, 42>;
348+
template struct LazyLitMatrix<index_by<int, char>, 42, 43>;
349+
350+
}
351+
352+
namespace TypeParameter {
353+
354+
template <typename Indices, InitFunc<Indices>... init>
355+
struct LazyLitMatrix; // expected-note {{here}}
356+
357+
template <
358+
typename...Indices,
359+
InitFunc<index_by<Indices>>... init
360+
>
361+
struct LazyLitMatrix<index_by<Indices...>, init...> {
362+
};
363+
364+
// FIXME: Explain why we didn't pick up the partial specialization - pack sizes don't match.
365+
template struct LazyLitMatrix<index_by<int, char>, float>;
366+
// expected-error@-1 {{instantiation of undefined template}}
367+
template struct LazyLitMatrix<index_by<int, char>, unsigned, float>;
368+
369+
}
370+
371+
namespace Invalid {
372+
373+
template <typename Indices, InitFunc<Indices>... init>
374+
struct LazyLitMatrix;
375+
376+
template <
377+
typename...Indices,
378+
InitFunc<index_by<Indices>> init
379+
// expected-error@-1 {{unexpanded parameter pack 'Indices'}}
380+
>
381+
struct LazyLitMatrix<index_by<Indices...>, init> {
382+
};
346383

347384
}
348385

0 commit comments

Comments
 (0)