Skip to content

Commit

Permalink
[clang][NFC] Move concepts::createSubstDiagAt from AST to Sema (#11…
Browse files Browse the repository at this point in the history
…3294)

This fixes layering violation introduced in
2fd01d7. The declaration is moved to
`SemaTemplateInstantiate` section of `Sema.h`, after the file where it's
implemented.
  • Loading branch information
Endilll authored and EricWF committed Oct 22, 2024
1 parent 5b3c91c commit 43587f8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
8 changes: 0 additions & 8 deletions clang/include/clang/AST/ExprConcepts.h
Original file line number Diff line number Diff line change
Expand Up @@ -489,14 +489,6 @@ class NestedRequirement : public Requirement {
return R->getKind() == RK_Nested;
}
};

using EntityPrinter = llvm::function_ref<void(llvm::raw_ostream &)>;

/// \brief create a Requirement::SubstitutionDiagnostic with only a
/// SubstitutedEntity and DiagLoc using Sema's allocator.
Requirement::SubstitutionDiagnostic *
createSubstDiagAt(Sema &S, SourceLocation Location, EntityPrinter Printer);

} // namespace concepts

/// C++2a [expr.prim.req]:
Expand Down
7 changes: 7 additions & 0 deletions clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -13435,6 +13435,13 @@ class Sema final : public SemaBase {
return CodeSynthesisContexts.size() > NonInstantiationEntries;
}

using EntityPrinter = llvm::function_ref<void(llvm::raw_ostream &)>;

/// \brief create a Requirement::SubstitutionDiagnostic with only a
/// SubstitutedEntity and DiagLoc using ASTContext's allocator.
concepts::Requirement::SubstitutionDiagnostic *
createSubstDiagAt(SourceLocation Location, EntityPrinter Printer);

///@}

//
Expand Down
10 changes: 5 additions & 5 deletions clang/lib/Sema/SemaExprCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9444,11 +9444,11 @@ Sema::BuildExprRequirement(
ExprResult Constraint = SubstExpr(IDC, MLTAL);
if (Constraint.isInvalid()) {
return new (Context) concepts::ExprRequirement(
concepts::createSubstDiagAt(*this, IDC->getExprLoc(),
[&](llvm::raw_ostream &OS) {
IDC->printPretty(OS, /*Helper=*/nullptr,
getPrintingPolicy());
}),
createSubstDiagAt(IDC->getExprLoc(),
[&](llvm::raw_ostream &OS) {
IDC->printPretty(OS, /*Helper=*/nullptr,
getPrintingPolicy());
}),
IsSimple, NoexceptLoc, ReturnTypeRequirement);
}
SubstitutedConstraintExpr =
Expand Down
7 changes: 3 additions & 4 deletions clang/lib/Sema/SemaTemplateInstantiate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2654,7 +2654,7 @@ QualType TemplateInstantiator::TransformSubstTemplateTypeParmPackType(

static concepts::Requirement::SubstitutionDiagnostic *
createSubstDiag(Sema &S, TemplateDeductionInfo &Info,
concepts::EntityPrinter Printer) {
Sema::EntityPrinter Printer) {
SmallString<128> Message;
SourceLocation ErrorLoc;
if (Info.hasSFINAEDiagnostic()) {
Expand All @@ -2675,12 +2675,11 @@ createSubstDiag(Sema &S, TemplateDeductionInfo &Info,
}

concepts::Requirement::SubstitutionDiagnostic *
concepts::createSubstDiagAt(Sema &S, SourceLocation Location,
EntityPrinter Printer) {
Sema::createSubstDiagAt(SourceLocation Location, EntityPrinter Printer) {
SmallString<128> Entity;
llvm::raw_svector_ostream OS(Entity);
Printer(OS);
const ASTContext &C = S.Context;
const ASTContext &C = Context;
return new (C) concepts::Requirement::SubstitutionDiagnostic{
/*SubstitutedEntity=*/C.backupStr(Entity),
/*DiagLoc=*/Location, /*DiagMessage=*/StringRef()};
Expand Down

0 comments on commit 43587f8

Please sign in to comment.