Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions clang/lib/Sema/SemaTemplateInstantiate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1736,23 +1736,13 @@ namespace {
SourceLocation RParenLoc,
std::optional<unsigned> Length,
ArrayRef<TemplateArgument> PartialArgs) {
if (SemaRef.CodeSynthesisContexts.back().Kind !=
Sema::CodeSynthesisContext::ConstraintNormalization)
return inherited::RebuildSizeOfPackExpr(OperatorLoc, Pack, PackLoc,
RParenLoc, Length, PartialArgs);

#ifndef NDEBUG
for (auto *Iter = TemplateArgs.begin(); Iter != TemplateArgs.end();
++Iter)
for (const TemplateArgument &TA : Iter->Args)
assert(TA.getKind() != TemplateArgument::Pack || TA.pack_size() == 1);
#endif
Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
SemaRef, /*NewSubstitutionIndex=*/0);
Decl *NewPack = TransformDecl(PackLoc, Pack);
if (!NewPack)
return ExprError();

Decl *NewPack = Pack;
if (SemaRef.CodeSynthesisContexts.back().Kind ==
Sema::CodeSynthesisContext::ConstraintNormalization) {
NewPack = TransformDecl(PackLoc, Pack);
if (!NewPack)
return ExprError();
}
return inherited::RebuildSizeOfPackExpr(OperatorLoc,
cast<NamedDecl>(NewPack), PackLoc,
RParenLoc, Length, PartialArgs);
Expand Down Expand Up @@ -1881,6 +1871,15 @@ Decl *TemplateInstantiator::TransformDecl(SourceLocation Loc, Decl *D) {
TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getPosition());

if (TTP->isParameterPack()) {
// We might not have an index for pack expansion when normalizing
// constraint expressions. In that case, resort to instantiation scopes
// for the transformed declarations.
if (SemaRef.ArgumentPackSubstitutionIndex == -1 &&
SemaRef.CodeSynthesisContexts.back().Kind ==
Sema::CodeSynthesisContext::ConstraintNormalization) {
return SemaRef.FindInstantiatedDecl(Loc, cast<NamedDecl>(D),
TemplateArgs);
}
assert(Arg.getKind() == TemplateArgument::Pack &&
"Missing argument pack");
Arg = getPackSubstitutedTemplateArgument(getSema(), Arg);
Expand Down
19 changes: 19 additions & 0 deletions clang/test/SemaTemplate/concepts-out-of-line-def.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,25 @@ C v;

} // namespace GH93099

namespace GH115098 {

template <typename... Ts> struct c {
template <typename T>
requires(sizeof...(Ts) > 0)
friend bool operator==(c, c);
};

template <typename... Ts> struct d {
template <typename T>
requires(sizeof...(Ts) > 0)
friend bool operator==(d, d);
};

template struct c<int>;
template struct d<int, int>;

} // namespace GH115098

namespace GH114685 {

template <typename T> struct ptr {
Expand Down
Loading