Skip to content

Commit

Permalink
[clang-tidy] Fix DanglingHandleCheck for the correct conversion opera…
Browse files Browse the repository at this point in the history
…tion between basic_string and basic_string_view.

Summary:
Fix DanglingHandleCheck to handle the final implementation of std::string and std::string_view.
These use a conversion operator instead of a conversion constructor.

Reviewers: hokein

Subscribers: klimek, xazax.hun, cfe-commits

Differential Revision: https://reviews.llvm.org/D41779

llvm-svn: 322002
  • Loading branch information
sbenzaquen committed Jan 8, 2018
1 parent 7183976 commit 1092cea
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 6 additions & 2 deletions clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp
Expand Up @@ -25,8 +25,12 @@ namespace {
ast_matchers::internal::BindableMatcher<Stmt>
handleFrom(const ast_matchers::internal::Matcher<RecordDecl> &IsAHandle,
const ast_matchers::internal::Matcher<Expr> &Arg) {
return cxxConstructExpr(hasDeclaration(cxxMethodDecl(ofClass(IsAHandle))),
hasArgument(0, Arg));
return expr(
anyOf(cxxConstructExpr(hasDeclaration(cxxMethodDecl(ofClass(IsAHandle))),
hasArgument(0, Arg)),
cxxMemberCallExpr(hasType(cxxRecordDecl(IsAHandle)),
callee(memberExpr(member(cxxConversionDecl()))),
on(Arg))));
}

ast_matchers::internal::Matcher<Stmt> handleFromTemporaryValue(
Expand Down
Expand Up @@ -45,10 +45,15 @@ class map {
value_type& operator[](Key&& key);
};

class basic_string_view;

class basic_string {
public:
basic_string();
basic_string(const char*);

operator basic_string_view() const noexcept;

~basic_string();
};

Expand All @@ -57,7 +62,6 @@ typedef basic_string string;
class basic_string_view {
public:
basic_string_view(const char*);
basic_string_view(const basic_string&);
};

typedef basic_string_view string_view;
Expand Down

0 comments on commit 1092cea

Please sign in to comment.