Issue |
127494
|
Summary |
[clang-tidy] misc-const-correctness false positive when using std::function default parameter
|
Labels |
clang-tidy,
false-positive
|
Assignees |
|
Reporter |
pkaff
|
```
#include <functional>
#include <sstream>
void func(std::function<void()> predicate = []() {})
{
static_cast<void>(predicate);
}
int main(int const /*argn*/, char * /*argv*/[])
{
std::ostringstream oss;
oss << "hello world";
func();
return 0;
}
```
Building this on Clang 19.1.7 arm64-apple-darwin24.2.0 (MacOS Sequoia 15.2) triggers a false positive for the check misc-const-correctness on the ostringstream variable:
```
error: variable 'oss' of type 'std::ostringstream' (aka 'basic_ostringstream<char>') can be declared 'const' [misc-const-correctness,-warnings-as-errors]
[build] 11 | std::ostringstream oss;
[build] | ^
[build] | const
```
while adding `const` clearly causes a compilation error.
I'm not able to reproduce this on godbolt with x86-64 clang (trunk) (or any of the older versions I tried either), so it seems like this might be MacOs specific: https://godbolt.org/z/9e47zxbcT.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs