Skip to content

Commit

Permalink
Ensure comparison of constraints creates a code synth context
Browse files Browse the repository at this point in the history
This is a regression from 6db007a that was reported in:
#62697

The assertion was because we require a code synthesis context for the
instantiation of templates, and this reproducer causes a comparison that
doesn't have a parent-template causing one to exists.

This patch fixes it by creating a ConstraintNormalization context.
  • Loading branch information
Erich Keane committed May 18, 2023
1 parent 153d9b9 commit fbd8f89
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
9 changes: 9 additions & 0 deletions clang/lib/Sema/SemaConcept.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,15 @@ static const Expr *SubstituteConstraintExpression(Sema &S, const NamedDecl *ND,
return ConstrExpr;

Sema::SFINAETrap SFINAE(S, /*AccessCheckingSFINAE=*/false);

Sema::InstantiatingTemplate Inst(
S, ND->getLocation(),
Sema::InstantiatingTemplate::ConstraintNormalization{},
const_cast<NamedDecl *>(ND), SourceRange{});

if (Inst.isInvalid())
return nullptr;

std::optional<Sema::CXXThisScopeRAII> ThisScope;
if (auto *RD = dyn_cast<CXXRecordDecl>(ND->getDeclContext()))
ThisScope.emplace(S, const_cast<CXXRecordDecl *>(RD), Qualifiers());
Expand Down
13 changes: 13 additions & 0 deletions clang/test/SemaTemplate/concepts-out-of-line-def.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,3 +399,16 @@ inline void W0<T7, 0>::W1<T8>::f(const T9 &) {}
} // namespace three_level

} // namespace MultilevelTemplateWithPartialSpecialization

namespace PR62697 {
template<typename>
concept c = true;

template<typename T>
struct s {
void f() requires c<void(T)>;
};

template<typename T>
void s<T>::f() requires c<void(T)> { }
}

0 comments on commit fbd8f89

Please sign in to comment.