Issue 97701
Summary [clang-tidy] `misc-const-correctness` false positive when calling a function with default lambda argument
Labels clang-tidy
Assignees
Reporter BobIsOnFire
    Hi! Here's minimal repro:

```c++
class A {};
void poison(void(*f)() = []{}) {}
void foo() {
    A a;
    a = {};
 poison();
}
```

I get following warning (godbolt: https://godbolt.org/z/cedY7o5ev):

```
<source>:4:5: warning: variable 'a' of type 'A' can be declared 'const' [misc-const-correctness]
 4 |     A a;
      |     ^
      |       const 
1 warning generated.
```

Even though I assign to `a` on the next line. Something is wrong with calling a function with a function pointer type (or `std::function`) that defaults to a lambda, it completely messes up the check -- note that it does not even use `a` in any way. Following changes would remove the false-positive:

* Removing the argument from `poison` function: https://godbolt.org/z/qvcz4jqE1
* Replacing lambda with `nullptr`: https://godbolt.org/z/cTTW84x15
* Explicitly passing a lambda to the call: https://godbolt.org/z/YEaWjY15r

Thanks in advance! Let me know if any other information is needed.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to