[llvm] [llvm][DebugInfo] Fix c++20 warnings in LVOptions.h (PR #79585)

David Spickett via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 26 03:58:01 PST 2024


https://github.com/DavidSpickett created https://github.com/llvm/llvm-project/pull/79585

Compiling with -DCMAKE_CXX_STANDARD=20 produces 228 warnings from this file due to:
```
LVOptions.h:515:16: warning: implicit capture of 'this' with a capture default of '=' is deprecated [-Wdeprecated-this-capture]
```

So I've changed these to explicitly list the captures, including `this`.

As llvm requires at least c++17, I think we could use `[=, *this]` instead. However when I did so I got a lot of errors about const. So on balance, explicitly listing the captures seems better than adding some kind of const cast to each one.

These and other warnings can be seen on the c++20 buildbot https://lab.llvm.org/buildbot/#/builders/249.

>From a53ae5d0777c6de67f35d5da4015e571f86f9012 Mon Sep 17 00:00:00 2001
From: David Spickett <david.spickett at linaro.org>
Date: Fri, 26 Jan 2024 11:53:29 +0000
Subject: [PATCH] [llvm][DebugInfo] Fix c++20 warnings in LVOptions.h

Compiling with -DCMAKE_CXX_STANDARD=20 produces 228 warnings
from this file due to:
```
LVOptions.h:515:16: warning: implicit capture of 'this' with a capture default of '=' is deprecated [-Wdeprecated-this-capture]
```

So I've changed these to explicitly list the captures, including
`this`.

As llvm requires at least c++17, I think we could use `[=, *this]`
instead. However when I did so I got a lot of errors about const.
So on balance, explicitly listing the captures seems better than
adding some kind of const cast to each one.

These and other warnings can be seen on the c++20 buildbot
https://lab.llvm.org/buildbot/#/builders/249.
---
 llvm/include/llvm/DebugInfo/LogicalView/Core/LVOptions.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/llvm/include/llvm/DebugInfo/LogicalView/Core/LVOptions.h b/llvm/include/llvm/DebugInfo/LogicalView/Core/LVOptions.h
index a0a360c0a434f91..a8bf33f9ad6b290 100644
--- a/llvm/include/llvm/DebugInfo/LogicalView/Core/LVOptions.h
+++ b/llvm/include/llvm/DebugInfo/LogicalView/Core/LVOptions.h
@@ -510,14 +510,14 @@ class LVPatterns final {
   template <typename T, typename U>
   void resolveGenericPatternMatch(T *Element, const U &Requests) {
     assert(Element && "Element must not be nullptr");
-    auto CheckPattern = [=]() -> bool {
+    auto CheckPattern = [this, Element]() -> bool {
       return (Element->isNamed() &&
               (matchGenericPattern(Element->getName()) ||
                matchGenericPattern(Element->getLinkageName()))) ||
              (Element->isTyped() &&
               matchGenericPattern(Element->getTypeName()));
     };
-    auto CheckOffset = [=]() -> bool {
+    auto CheckOffset = [this, Element]() -> bool {
       return matchOffsetPattern(Element->getOffset());
     };
     if ((options().getSelectGenericPattern() && CheckPattern()) ||
@@ -530,12 +530,12 @@ class LVPatterns final {
   template <typename U>
   void resolveGenericPatternMatch(LVLine *Line, const U &Requests) {
     assert(Line && "Line must not be nullptr");
-    auto CheckPattern = [=]() -> bool {
+    auto CheckPattern = [this, Line]() -> bool {
       return matchGenericPattern(Line->lineNumberAsStringStripped()) ||
              matchGenericPattern(Line->getName()) ||
              matchGenericPattern(Line->getPathname());
     };
-    auto CheckOffset = [=]() -> bool {
+    auto CheckOffset = [this, Line]() -> bool {
       return matchOffsetPattern(Line->getAddress());
     };
     if ((options().getSelectGenericPattern() && CheckPattern()) ||



More information about the llvm-commits mailing list