[PATCH] D103380: [C++20] Support for lambdas in unevaluated context

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 1 08:18:11 PDT 2021


aaron.ballman added a comment.

Thanks for working on this!

> It does not implement temp.deduct/9.

Is there a reason why?



================
Comment at: clang/lib/Sema/SemaConcept.cpp:44
     } else if (auto *OO = dyn_cast<CXXOperatorCallExpr>(E)) {
-      Op = OO->getOperator();
-      LHS = OO->getArg(0);
-      RHS = OO->getArg(1);
+      // If OO is not || or && it might not have exactly 2 arguments
+      if (OO->getNumArgs() == 2) {
----------------



================
Comment at: clang/test/CXX/expr/expr.prim/expr.prim.lambda/p2-unevaluated.cpp:1
+// RUN: %clang_cc1 -std=c++20 %s -verify
+
----------------
This test doesn't really have anything to do with [expr.prim.lambda]p2 as it appears in C++20 and later, it's more testing the words that used to live in p2 in C++17 and earlier no longer apply.

I think the functionality in the test is good, but should either be moved to the correct file based on what property is being tested or should be moved out of the `CXX` directory and into `SemaCXX` (or a combination of both). I'd recommend going through the examples presented in the wording of https://wg21.link/p0315r4 and make a test for each.


================
Comment at: clang/test/CXX/expr/expr.prim/expr.prim.lambda/p2-unevaluated.cpp:4
+template <auto> struct Nothing {};
+Nothing<[]() { return 0; }()> nothing;
+
----------------
I'd appreciate a test that shows you can also use a lambda that is not immediately invoked.


================
Comment at: clang/test/CXX/expr/expr.prim/expr.prim.lambda/p2-unevaluated.cpp:20
+
+
+
----------------
I think it's important to have some tests that show two lambdas are never equivalent (http://eel.is/c++draft/temp.over.link#5.sentence-4). Given the intent specified in the standard, I think a super useful case would be:
```
template <typename Ty, typename Uy>
auto func() -> decltype(Ty{}.operator()(Uy{})) { return 1; }

int main() {
  auto lambda = [](auto i){ return i; };
  func<decltype(lambda), int>();
}
```
I *think* that will cause the lambda to be mangled as part of the trailing return type.

Other tests would be typical type equivalence tests (like using `std::is_same`).


================
Comment at: clang/test/CXX/expr/expr.prim/expr.prim.lambda/p2-unevaluated.cpp:26
+// expected-note at -2 {{substitution failure}}
\ No newline at end of file

----------------
Can you add the newline to the end of the file?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103380/new/

https://reviews.llvm.org/D103380



More information about the cfe-commits mailing list