llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.96k stars 11.94k forks source link

False positive from clang-analyzer-deadcode.DeadStores with std::ref and std::bind #53597

Open randombit opened 2 years ago

randombit commented 2 years ago
#include <functional>
#include <stdio.h>

void run(int v)
   {
   printf("%d\n", v);
   }

int main()
   {
   int v = 5;
   auto f = std::bind(run, std::ref(v));
   f();

   v = 10;
   f();
   }

The printf in run is just to "prove" that the second store is used.

1 warning generated.
/home/jack/ref.cpp:15:4: warning: Value stored to 'v' is never read [clang-analyzer-deadcode.DeadStores]
   v = 10;
   ^   ~~
/home/jack/ref.cpp:15:4: note: Value stored to 'v' is never read
   v = 10;
   ^   ~~
$ clang-tidy --version
LLVM (http://llvm.org/):
  LLVM version 13.0.0
  Optimized build.
  Default target: x86_64-pc-linux-gnu
  Host CPU: skylake
CaseyCarter commented 2 years ago

Sorry: closed inadvertently by typo.