Closed
Description
When trying to analyze the following code with clang-tidy, I get a crash:
//minimal.cpp
#include <functional>
auto f() -> std::function<int()> {
int v;
auto c = [&v]() {
return v;
};
return c;
}
auto main() -> int { return f()(); }
The function f
returns a std::function
wrapping a lambda with a dangling reference in its capture. The crash doesn't happen if I return a lambda instead of a std::function
, nor if I capture by value.
Command
clang-tidy-16 minimal.cpp -- -std=c++20
Crash report:
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: clang-tidy-16 minimal.cpp -- -std=c++23
1. <eof> parser at end of file
2. While analyzing stack:
#0 Calling f() at line 12
#1 Calling main()
#0 0x00007fd657365796 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/lib/llvm-16/bin/../lib/libLLVM-16.so.1+0xfc9796)
#1 0x00007fd6573639e0 llvm::sys::RunSignalHandlers() (/usr/lib/llvm-16/bin/../lib/libLLVM-16.so.1+0xfc79e0)
#2 0x00007fd657365f6b (/usr/lib/llvm-16/bin/../lib/libLLVM-16.so.1+0xfc9f6b)
#3 0x00007fd655ed5fd0 (/lib/x86_64-linux-gnu/libc.so.6+0x3bfd0)
#4 0x00007fd656387c50 vtable for __cxxabiv1::__si_class_type_info (/lib/x86_64-linux-gnu/libstdc++.so.6+0x20bc50)
Segmentation fault (core dumped)
$ clang-tidy-16 --version
Debian LLVM version 16.0.6
Optimized build.
But the crash happens with clang-tidy 16, 17, 18, as well as the system 14.0.6 (inside a debian:latest docker) and the system 15.0.7 (on a Ubuntu 23.04 machine).