Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
29 changes: 16 additions & 13 deletions clang/lib/Sema/SemaConcept.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,14 +264,6 @@ class HashParameterMapping : public RecursiveASTVisitor<HashParameterMapping> {

UnsignedOrNone OuterPackSubstIndex;

TemplateArgument getPackSubstitutedTemplateArgument(TemplateArgument Arg) {
assert(*SemaRef.ArgPackSubstIndex < Arg.pack_size());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we lose this assert, was this on purpose?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's still there, which is guaranteed by ArrayRef.

Arg = Arg.pack_begin()[*SemaRef.ArgPackSubstIndex];
if (Arg.isPackExpansion())
Arg = Arg.getPackExpansionPattern();
return Arg;
}

bool shouldVisitTemplateInstantiations() const { return true; }

public:
Expand All @@ -294,7 +286,7 @@ class HashParameterMapping : public RecursiveASTVisitor<HashParameterMapping> {
assert(Arg.getKind() == TemplateArgument::Pack &&
"Missing argument pack");

Arg = getPackSubstitutedTemplateArgument(Arg);
Arg = SemaRef.getPackSubstitutedTemplateArgument(Arg);
}

UsedTemplateArgs.push_back(
Expand All @@ -312,7 +304,7 @@ class HashParameterMapping : public RecursiveASTVisitor<HashParameterMapping> {
if (NTTP->isParameterPack() && SemaRef.ArgPackSubstIndex) {
assert(Arg.getKind() == TemplateArgument::Pack &&
"Missing argument pack");
Arg = getPackSubstitutedTemplateArgument(Arg);
Arg = SemaRef.getPackSubstitutedTemplateArgument(Arg);
}

UsedTemplateArgs.push_back(
Expand All @@ -325,8 +317,11 @@ class HashParameterMapping : public RecursiveASTVisitor<HashParameterMapping> {
}

bool TraverseDecl(Decl *D) {
if (auto *VD = dyn_cast<ValueDecl>(D))
if (auto *VD = dyn_cast<ValueDecl>(D)) {
if (auto *Var = dyn_cast<VarDecl>(VD))
TraverseStmt(Var->getInit());
return TraverseType(VD->getType());
}

return inherited::TraverseDecl(D);
}
Expand Down Expand Up @@ -363,6 +358,14 @@ class HashParameterMapping : public RecursiveASTVisitor<HashParameterMapping> {
return inherited::TraverseTemplateArgument(Arg);
}

bool TraverseSizeOfPackExpr(SizeOfPackExpr *SOPE) {
return TraverseDecl(SOPE->getPack());
}

bool VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E) {
return inherited::TraverseStmt(E->getReplacement());
}

void VisitConstraint(const NormalizedConstraintWithParamMapping &Constraint) {
if (!Constraint.hasParameterMapping()) {
for (const auto &List : TemplateArgs)
Expand Down Expand Up @@ -2083,8 +2086,8 @@ bool SubstituteParameterMappings::substitute(ConceptIdConstraint &CC) {
/*UpdateArgsWithConversions=*/false))
return true;
auto TemplateArgs = *MLTAL;
TemplateArgs.replaceOutermostTemplateArguments(
TemplateArgs.getAssociatedDecl(0).first, CTAI.SugaredConverted);
TemplateArgs.replaceOutermostTemplateArguments(CSE->getNamedConcept(),
CTAI.SugaredConverted);
return SubstituteParameterMappings(SemaRef, &TemplateArgs, ArgsAsWritten,
InFoldExpr)
.substitute(CC.getNormalizedConstraint());
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/Sema/SemaTemplateDeduction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6718,6 +6718,10 @@ struct MarkUsedTemplateParameterVisitor : DynamicRecursiveASTVisitor {
}
return true;
}

bool TraverseSizeOfPackExpr(SizeOfPackExpr *SOPE) override {
return TraverseDecl(SOPE->getPack());
}
};
}

Expand Down
71 changes: 71 additions & 0 deletions clang/test/SemaTemplate/concepts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1333,4 +1333,75 @@ static_assert(__cpp17_iterator<not_move_constructible>); \
// expected-note@#is_move_constructible_v {{because 'is_move_constructible_v<parameter_mapping_regressions::case3::not_move_constructible>' evaluated to false}}
}

namespace case4 {

template<bool b>
concept bool_ = b;

template<typename... Ts>
concept unary = bool_<sizeof...(Ts) == 1>;

static_assert(!unary<>);
static_assert(unary<void>);

}

namespace case5 {

template<int size>
concept true1 = size == size;

template<typename... Ts>
concept true2 = true1<sizeof...(Ts)>;

template<typename... Ts>
concept true3 = true2<Ts...>;

static_assert(true3<void>);

}

namespace case6 {

namespace std {
template <int __v>
struct integral_constant {
static const int value = __v;
};

template <class _Tp, class... _Args>
constexpr bool is_constructible_v = __is_constructible(_Tp, _Args...);

template <class _From, class _To>
constexpr bool is_convertible_v = __is_convertible(_From, _To);

template <class>
struct tuple_size;

template <class _Tp>
constexpr decltype(sizeof(int)) tuple_size_v = tuple_size<_Tp>::value;
} // namespace std

template <int N, int X>
concept FixedExtentConstructibleFromExtent = X == N;

template <int Extent>
struct span {
int static constexpr extent = Extent;
template <typename R, int N = std::tuple_size_v<R>>
requires(FixedExtentConstructibleFromExtent<extent, N>)
span(R);
};

template <class, int>
struct array {};

template <class _Tp, decltype(sizeof(int)) _Size>
struct std::tuple_size<array<_Tp, _Size>> : integral_constant<_Size> {};

static_assert(std::is_convertible_v<array<int, 3>, span<3>>);
static_assert(!std::is_constructible_v<span<4>, array<int, 3>>);

}

}