[llvm-bugs] [Bug 45398] New: -Wunused-lambda-capture: false positive on `if constexpr`

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Apr 2 01:38:57 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=45398

            Bug ID: 45398
           Summary: -Wunused-lambda-capture: false positive on `if
                    constexpr`
           Product: clang
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++17
          Assignee: unassignedclangbugs at nondot.org
          Reporter: gribozavr at gmail.com
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk

-Wunused-lambda-capture produces a false positive on lambdas that use captured
variables within inactive branches of `if constexpr`.

$ ./bin/clang++ --version
clang version 11.0.0 (git at github.com:llvm/llvm-project.git
cdce2fe561eb6e63d77d1d589e521a8e2afb1eef)
...
$ cat /tmp/unused-lambda-capture-false-positive.cc
template <int>
struct A {};
struct B {
  template <typename T, bool flag>
  void Top(T t, int n) {
    auto lambda = [t, n, this](auto arg) {
      if constexpr (flag) {
        UndefinedFunction(t, n);
      } else {
        TopImpl<A<arg>>();
      }
    };
  }
  template <typename U>
  void TopImpl() {}
};
void Test(B* b) {
  b->Top<int, false>(0, 0);
}
$ ./bin/clang++ -c -std=gnu++17 -Wunused-lambda-capture
/tmp/unused-lambda-capture-false-positive.cc
/tmp/unused-lambda-capture-false-positive.cc:6:20: warning: lambda capture 't'
is not used [-Wunused-lambda-capture]
    auto lambda = [t, n, this](auto arg) {
                   ^
/tmp/unused-lambda-capture-false-positive.cc:18:6: note: in instantiation of
function template specialization 'B::Top<int, false>' requested here
  b->Top<int, false>(0, 0);
     ^
/tmp/unused-lambda-capture-false-positive.cc:6:23: warning: lambda capture 'n'
is not used [-Wunused-lambda-capture]
    auto lambda = [t, n, this](auto arg) {
                      ^
/tmp/unused-lambda-capture-false-positive.cc:6:26: warning: lambda capture
'this' is not used [-Wunused-lambda-capture]
    auto lambda = [t, n, this](auto arg) {
                         ^
3 warnings generated.

ANALYSIS

The false positive on `this` might be a dup of
https://bugs.llvm.org/show_bug.cgi?id=36880, however false positives on `t` and
`n` seem diffirent.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200402/89105b6a/attachment.html>


More information about the llvm-bugs mailing list