Closed
Description
Given the following snippet of code, copied from the example in https://clang.llvm.org/extra/clang-tidy/checks/bugprone-dangling-handle.html
#include <string>
#include <string_view>
#include <vector>
using namespace std;
int main() {
string_view View = string(); // View will dangle.
string A;
View = A + "A"; // still dangle.
vector<string_view> V;
V.push_back(string()); // V[0] is dangling.
V.resize(3, string()); // V[1] and V[2] will also dangle.
}
std::string_view f() {
// All these return values will dangle.
return string();
string S;
return S;
char Array[10]{};
return Array;
}
Running this command does not catch any of the sample errors:
llvm/llvm-project/build/bin/clang-tidy --extra-arg="--std=c++17" --checks="bugprone-dangling-handle,-clang-diagnostic-dangling-gsl,-clang-diagnostic-return-stack-address" bugprone_dangling_handle.cpp
Expected results: The sample errors should trigger bugprone-dangling-handle checks.