Skip to content

Commit c24d10f

Browse files
committed
[cxx-interop] Elaborate comment for use of hasActiveRequest()
1 parent ad0cde7 commit c24d10f

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8795,10 +8795,18 @@ static bool hasUnsafeType(Evaluator &evaluator, clang::QualType clangType) {
87958795
// so we don't need to check the bases whether they are shared references.
87968796
auto req = ClangDeclExplicitSafety({recordDecl, false});
87978797
if (evaluator.hasActiveRequest(req))
8798-
// Cycles are allowed in templates, e.g.:
8798+
// Normally, using hasActiveRequest() to avoid cycles is an anti-pattern
8799+
// because cycles should be treated as errors. However, cycles are allowed
8800+
// in C++ template, e.g.:
8801+
//
87998802
// template <typename> class Foo { ... }; // throws away template arg
88008803
// template <typename T> class Bar : Foo<Bar<T>> { ... };
8801-
// We need to avoid them here.
8804+
//
8805+
// A common use case of cyclic templates is the CRTP pattern.
8806+
//
8807+
// We need to avoid request cycles, so if there is already an active
8808+
// request for this type, just assume it is not explicitly unsafe for now
8809+
// (i.e., as if it were unspecified).
88028810
return false;
88038811
return evaluateOrDefault(evaluator, req, ExplicitSafety::Unspecified) ==
88048812
ExplicitSafety::Unsafe;

0 commit comments

Comments
 (0)