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

False positive unused-lambda-capture with if constexpr #63031

Closed
chrchr-github opened this issue May 31, 2023 · 1 comment
Closed

False positive unused-lambda-capture with if constexpr #63031

chrchr-github opened this issue May 31, 2023 · 1 comment
Labels
clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer duplicate Resolved as duplicate false-positive Warning fires when it should not

Comments

@chrchr-github
Copy link

chrchr-github commented May 31, 2023

#include <type_traits>
#include <vector>
#include <algorithm>

template<typename T>
bool f(int j, std::vector<int>& v) {
  const bool b = j > 0;

  std::for_each(v.begin(), v.end(), [b](auto& i) {	
    if constexpr (std::is_same_v<T, int>) {
      i += i ? 5 : 7;
    }
    else if (b)
    {
      i += 1;
    }
  });
  return b;
}

void g(std::vector<int>& w) {
    f<int>(0, w);
}
<source>:9:38: warning: lambda capture 'b' is not used [-Wunused-lambda-capture]
  std::for_each(v.begin(), v.end(), [b](auto& i) {      
                                     ^
<source>:22:5: note: in instantiation of function template specialization 'f<int>' requested here
    f<int>(0, w);
    ^

https://godbolt.org/z/4Ejczrv5n

The warning is correct on its face, but not actionable.

@EugeneZelenko EugeneZelenko added clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer false-positive Warning fires when it should not and removed new issue labels May 31, 2023
@wheatman
Copy link
Contributor

wheatman commented Nov 4, 2023

duplicate of #34798

@wheatman wheatman closed this as not planned Won't fix, can't repro, duplicate, stale Nov 4, 2023
@wheatman wheatman added the duplicate Resolved as duplicate label Nov 4, 2023
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 duplicate Resolved as duplicate false-positive Warning fires when it should not
Projects
None yet
Development

No branches or pull requests

3 participants