Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 26, 2024

Conversation

DavidSpickett
Copy link
Collaborator

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.

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.
@llvmbot
Copy link
Member

llvmbot commented Jan 26, 2024

@llvm/pr-subscribers-debuginfo

Author: David Spickett (DavidSpickett)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/79585.diff

1 Files Affected:

  • (modified) llvm/include/llvm/DebugInfo/LogicalView/Core/LVOptions.h (+4-4)
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()) ||

@DavidSpickett
Copy link
Collaborator Author

If the chosen substitute is ok, I can do the same for more of these warnings.

Copy link
Member

@CarlosAlbertoEnciso CarlosAlbertoEnciso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking at those warnings. The changes look good.

@DavidSpickett DavidSpickett merged commit 7b7d2dd into llvm:main Jan 26, 2024
@DavidSpickett DavidSpickett deleted the c++20 branch January 26, 2024 14:35
@dwblaikie
Copy link
Collaborator

I'd generally suggest if a lambda doesn't escape its scope, especially when they're short/simple like this (you can see the whole lambda and its call on a page) we should use [&] by default to keep things simple.

Also, it's a bit quirky to define lambdas for a single call a few lines later - perhaps this code would be more clear if it were written without lambdas, and with a possible series of if statements?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants