[PATCH] D89332: [clang-tidy] performance-unnecessary-copy-initialization: Always allow std::function to be copied.
Felix Berger via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 21 14:23:31 PDT 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1c1f794c2b64: Always allow std::function to be copied. (authored by flx).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D89332/new/
https://reviews.llvm.org/D89332
Files:
clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
Index: clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
@@ -405,3 +405,58 @@
ExpensiveToCopyType Orig;
const ExpensiveToCopyType Copy = freeFunctionWithDefaultArg(&Orig);
}
+
+namespace std {
+inline namespace __1 {
+
+template <class>
+class function;
+template <class R, class... Args>
+class function<R(Args...)> {
+public:
+ function();
+ function(const function &other);
+ R operator()(Args &&...args) const;
+};
+
+} // namespace __1
+} // namespace std
+
+void negativeStdFunction() {
+ std::function<int()> Orig;
+ std::function<int()> Copy = Orig;
+ int i = Orig();
+}
+
+using Functor = std::function<int()>;
+
+void negativeAliasedStdFunction() {
+ Functor Orig;
+ Functor Copy = Orig;
+ int i = Orig();
+}
+
+typedef std::function<int()> TypedefFunc;
+
+void negativeTypedefedStdFunction() {
+ TypedefFunc Orig;
+ TypedefFunc Copy = Orig;
+ int i = Orig();
+}
+
+namespace fake {
+namespace std {
+template <class R, class... Args>
+struct function {
+ // Custom copy constructor makes it expensive to copy;
+ function(const function &);
+};
+} // namespace std
+
+void positiveFakeStdFunction(std::function<void(int)> F) {
+ auto Copy = F;
+ // CHECK-MESSAGES: [[@LINE-1]]:8: warning: local copy 'Copy' of the variable 'F' is never modified;
+ // CHECK-FIXES: const auto& Copy = F;
+}
+
+} // namespace fake
Index: clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
===================================================================
--- clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
+++ clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
@@ -63,8 +63,10 @@
declStmt(
has(varDecl(hasLocalStorage(),
hasType(qualType(
- hasCanonicalType(
- matchers::isExpensiveToCopy()),
+ hasCanonicalType(allOf(
+ matchers::isExpensiveToCopy(),
+ unless(hasDeclaration(namedDecl(
+ hasName("::std::function")))))),
unless(hasDeclaration(namedDecl(
matchers::matchesAnyListedName(
AllowedTypes)))))),
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89332.299805.patch
Type: text/x-patch
Size: 2759 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201021/799ab742/attachment-0001.bin>
More information about the cfe-commits
mailing list