This is an archive of the discontinued LLVM Phabricator instance.

[Clang] Fix constraint checking of non-generic lambdas.
ClosedPublic

Authored by cor3ntin on Jul 3 2023, 10:09 AM.

Details

Summary

A lambda call operator can be a templated entity -
and therefore have constraints while not being a function template

template<class T> void f() {
  []() requires false { }();
}

In that case, we would check the constraints of the call operator
which is non-viable. However, we would find a viable candidate:
the conversion operator to function pointer, and use it to
perform a surrogate call.
These constraints were not checked because:

  • We never check the constraints of surrogate functions
  • The lambda conversion operator has non constraints.

From the wording, it is not clear what the intent is but
it seems reasonable to expect the constraints of the lambda conversion
operator to be checked and it is consistent with GCC and MSVC.

This patch also improve the diagnostics for constraint failure
on surrogate calls.

Fixes #63181

Diff Detail

Event Timeline

cor3ntin created this revision.Jul 3 2023, 10:09 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 3 2023, 10:09 AM
cor3ntin requested review of this revision.Jul 3 2023, 10:09 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 3 2023, 10:09 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
cor3ntin added reviewers: cjdb, Restricted Project.Jul 3 2023, 10:09 AM
cor3ntin updated this revision to Diff 536976.Jul 4 2023, 12:39 AM
  • Move the check for lambda conversion operator in CheckFunmctionConstraints so that it is always performed.
  • Add tests of constraints referring to parameters of the lambda
aaron.ballman added inline comments.
clang/include/clang/Basic/DiagnosticSemaKinds.td
4736–4737

I think "candidate surrogate function" is a bit... technical for a user-facing diagnostic (we don't seem to use it any other diagnostics). Perhaps we should go with conversion candidate function instead as we did for note_ovl_surrogate_cand?

clang/lib/Sema/SemaConcept.cpp
685
clang/lib/Sema/SemaLambda.cpp
1636–1638
clang/lib/Sema/SemaOverload.cpp
14999
cor3ntin updated this revision to Diff 541858.Jul 19 2023, 12:09 AM
cor3ntin marked 3 inline comments as done.

Address Aaron's feedback

aaron.ballman accepted this revision.Jul 20 2023, 12:21 PM

LGTM aside from some questions about comments in the test.

clang/test/SemaTemplate/concepts.cpp
530–531

Comment is now stale and can be removed?

578–579

This one can also be removed?

This revision is now accepted and ready to land.Jul 20 2023, 12:21 PM
This revision was automatically updated to reflect the committed changes.