Skip to content

Commit cdf8663

Browse files
committed
Fix handlind of concept-id which appear as an atomic constraint
1 parent a436ed4 commit cdf8663

File tree

4 files changed

+122
-120
lines changed

4 files changed

+122
-120
lines changed

clang/include/clang/AST/ASTConcept.h

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ class Expr;
3232
class NamedDecl;
3333
struct PrintingPolicy;
3434

35+
/// Pairs of unsatisfied atomic constraint expressions along with the
36+
/// substituted constraint expr, if the template arguments could be
37+
/// substituted into them, or a diagnostic if substitution resulted in
38+
/// an invalid expression.
39+
using UnsatisfiedConstraintRecord =
40+
llvm::PointerUnion<const Expr *, const ConceptReference *,
41+
std::pair<SourceLocation, StringRef> *>;
42+
3543
/// The result of a constraint satisfaction check, containing the necessary
3644
/// information to diagnose an unsatisfied constraint.
3745
class ConstraintSatisfaction : public llvm::FoldingSetNode {
@@ -50,15 +58,14 @@ class ConstraintSatisfaction : public llvm::FoldingSetNode {
5058
: ConstraintOwner(ConstraintOwner), TemplateArgs(TemplateArgs) {}
5159

5260
using SubstitutionDiagnostic = std::pair<SourceLocation, StringRef>;
53-
using Detail = llvm::PointerUnion<const Expr *, SubstitutionDiagnostic *>;
5461

5562
bool IsSatisfied = false;
5663
bool ContainsErrors = false;
5764

5865
/// \brief The substituted constraint expr, if the template arguments could be
5966
/// substituted into them, or a diagnostic if substitution resulted in an
6067
/// invalid expression.
61-
llvm::SmallVector<Detail, 4> Details;
68+
llvm::SmallVector<UnsatisfiedConstraintRecord, 4> Details;
6269

6370
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &C) {
6471
Profile(ID, C, ConstraintOwner, TemplateArgs);
@@ -76,13 +83,6 @@ class ConstraintSatisfaction : public llvm::FoldingSetNode {
7683
}
7784
};
7885

79-
/// Pairs of unsatisfied atomic constraint expressions along with the
80-
/// substituted constraint expr, if the template arguments could be
81-
/// substituted into them, or a diagnostic if substitution resulted in
82-
/// an invalid expression.
83-
using UnsatisfiedConstraintRecord =
84-
llvm::PointerUnion<const Expr *, std::pair<SourceLocation, StringRef> *>;
85-
8686
/// \brief The result of a constraint satisfaction check, containing the
8787
/// necessary information to diagnose an unsatisfied constraint.
8888
///
@@ -102,6 +102,10 @@ struct ASTConstraintSatisfaction final :
102102
return getTrailingObjects() + NumRecords;
103103
}
104104

105+
ArrayRef<UnsatisfiedConstraintRecord> records() const {
106+
return {begin(), end()};
107+
}
108+
105109
ASTConstraintSatisfaction(const ASTContext &C,
106110
const ConstraintSatisfaction &Satisfaction);
107111
ASTConstraintSatisfaction(const ASTContext &C,
@@ -287,6 +291,11 @@ class TypeConstraint {
287291
}
288292
};
289293

294+
/// Insertion operator for diagnostics. This allows sending TemplateName's
295+
/// into a diagnostic with <<.
296+
const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,
297+
const ConceptReference *C);
298+
290299
} // clang
291300

292301
#endif // LLVM_CLANG_AST_ASTCONCEPT_H

clang/lib/AST/ASTConcept.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ CreateUnsatisfiedConstraintRecord(const ASTContext &C,
2727
new (TrailingObject) UnsatisfiedConstraintRecord(nullptr);
2828
else if (const auto *E = llvm::dyn_cast<const Expr *>(Detail))
2929
new (TrailingObject) UnsatisfiedConstraintRecord(E);
30+
else if (const auto *Concept =
31+
llvm::dyn_cast<const ConceptReference *>(Detail))
32+
new (TrailingObject) UnsatisfiedConstraintRecord(Concept);
3033
else {
3134
auto &SubstitutionDiagnostic =
3235
*cast<std::pair<SourceLocation, StringRef> *>(Detail);
@@ -112,6 +115,19 @@ void ConceptReference::print(llvm::raw_ostream &OS,
112115
}
113116
}
114117

118+
const StreamingDiagnostic &clang::operator<<(const StreamingDiagnostic &DB,
119+
const ConceptReference *C) {
120+
std::string NameStr;
121+
llvm::raw_string_ostream OS(NameStr);
122+
LangOptions LO;
123+
LO.CPlusPlus = true;
124+
LO.Bool = true;
125+
OS << '\'';
126+
C->print(OS, PrintingPolicy(LO));
127+
OS << '\'';
128+
return DB << NameStr;
129+
}
130+
115131
concepts::ExprRequirement::ExprRequirement(
116132
Expr *E, bool IsSimple, SourceLocation NoexceptLoc,
117133
ReturnTypeRequirement Req, SatisfactionStatus Status,

0 commit comments

Comments
 (0)