[PATCH] D41779: [clang-tidy] Fix DanglingHandleCheck for the correct conversion operation between basic_string and basic_string_view.
Samuel Benzaquen via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 5 10:45:05 PST 2018
sbenza created this revision.
sbenza added a reviewer: hokein.
Herald added subscribers: cfe-commits, xazax.hun, klimek.
Fix DanglingHandleCheck to handle the final implementation of std::string and std::string_view.
These use a conversion operator instead of a conversion constructor.
Repository:
rCTE Clang Tools Extra
https://reviews.llvm.org/D41779
Files:
clang-tidy/bugprone/DanglingHandleCheck.cpp
test/clang-tidy/bugprone-dangling-handle.cpp
Index: test/clang-tidy/bugprone-dangling-handle.cpp
===================================================================
--- test/clang-tidy/bugprone-dangling-handle.cpp
+++ test/clang-tidy/bugprone-dangling-handle.cpp
@@ -45,19 +45,23 @@
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();
};
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;
Index: clang-tidy/bugprone/DanglingHandleCheck.cpp
===================================================================
--- clang-tidy/bugprone/DanglingHandleCheck.cpp
+++ clang-tidy/bugprone/DanglingHandleCheck.cpp
@@ -25,8 +25,12 @@
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(
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41779.128772.patch
Type: text/x-patch
Size: 1616 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180105/4ae31bb5/attachment.bin>
More information about the cfe-commits
mailing list