[PATCH] D137172: [Clang] Implement CWG2358 Explicit capture of value

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 1 11:46:24 PDT 2022


aaron.ballman added a comment.

Precommit CI seems to have caught valid failures this time.



================
Comment at: clang/lib/Sema/SemaDeclCXX.cpp:152
 bool CheckDefaultArgumentVisitor::VisitLambdaExpr(const LambdaExpr *Lambda) {
-  // C++11 [expr.lambda.prim]p13:
-  //   A lambda-expression appearing in a default argument shall not
-  //   implicitly or explicitly capture any entity.
-  if (Lambda->capture_begin() == Lambda->capture_end())
-    return false;
-
-  return S.Diag(Lambda->getBeginLoc(), diag::err_lambda_capture_default_arg);
+  // [expr.prim.lambda.capture]/p9
+  // a lambda-expression appearing in a default argument cannot implicitly or explicitly capture any local entity.
----------------



================
Comment at: clang/lib/Sema/SemaDeclCXX.cpp:157
+  bool Invalid = false;
+  for(const LambdaCapture& LC : Lambda->captures()) {
+    if(!Lambda->isInitCapture(&LC))
----------------



================
Comment at: clang/lib/Sema/SemaDeclCXX.cpp:158
+  for(const LambdaCapture& LC : Lambda->captures()) {
+    if(!Lambda->isInitCapture(&LC))
+      return S.Diag(LC.getLocation(), diag::err_lambda_capture_default_arg);
----------------



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137172



More information about the cfe-commits mailing list