Skip to content

clang-tidy: bugprone-dangling-handle does not work #54984

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
cscrimge opened this issue Apr 19, 2022 · 3 comments
Closed

clang-tidy: bugprone-dangling-handle does not work #54984

cscrimge opened this issue Apr 19, 2022 · 3 comments

Comments

@cscrimge
Copy link

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.

@cscrimge cscrimge changed the title bugprone-dangling-handle does not work clang-tidy: bugprone-dangling-handle does not work Apr 19, 2022
@llvmbot
Copy link
Member

llvmbot commented Apr 19, 2022

@llvm/issue-subscribers-clang-tidy

@PiotrZSL
Copy link
Member

PiotrZSL commented Apr 15, 2023

Issues in main are detected once #38779 get fixed.
Issues in f functions are still not detected.

Looks like support for "return" is not implemented in check.

@PiotrZSL
Copy link
Member

Fixed by f2e5000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants