Skip to content
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

[clang] -Weverything option produces a warning(-Wshadow-uncaptured-local) when explicitly capturing a local value using std::move() #81307

Open
Wayonb opened this issue Feb 9, 2024 · 4 comments
Labels
clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer

Comments

@Wayonb
Copy link

Wayonb commented Feb 9, 2024

This bug is similar to #71976, except my scenario deals with move capture syntax.

This is a standard C++ pattern when moving objects into a lambda. Or is there something I am missing?

From my repo, the warning only happens when -Weverything option is used and not when -Wshadow-uncaptured-local is used.
https://godbolt.org/z/6v1jbx5f1

#include <utility>

void foo();

int main() {
    foo();
    return 0;
}

void foo() {
    int* a = new int(1);
  ([a = std::move(a)]() {
    *a = 2;
  })();
}
@github-actions github-actions bot added the clang Clang issues not falling into any other category label Feb 9, 2024
@EugeneZelenko EugeneZelenko added clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer and removed clang Clang issues not falling into any other category labels Feb 9, 2024
@shafik
Copy link
Collaborator

shafik commented Feb 10, 2024

CC @cor3ntin

@cor3ntin
Copy link
Contributor

Cc @Fznamznon @erichkeane

@jarzec
Copy link

jarzec commented Aug 23, 2024

I think all cases whenever initialization is used get flagged. I believe initializations with std::move, std::forward and std::as_const (anything else?) should not be flagged.
This is true for version 18.1.6.

@jarzec
Copy link

jarzec commented Oct 4, 2024

I have confirmed for that v17.0.1, 18.1.0 and 19.1.0 and the original example on Godbolt with all the specific shadow flags listed here:
-Wshadow-field -Wshadow-field-in-constructor -Wshadow-field-in-constructor-modified -Wshadow-ivar -Wshadow-uncaptured-local
std::move() in capture is not flagged, while if -Wshadow or -Wshadow-all is added to the above set of flags the code does not compile anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer
Projects
None yet
Development

No branches or pull requests

5 participants