aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergio Martins <smartins@kde.org>2019-01-13 21:43:26 +0000
committerSergio Martins <smartins@kde.org>2019-01-13 21:46:12 +0000
commit1ac59a00dc6886ba6e1259daac8980c92230fc2a (patch)
tree618f31a4d0072dae017d477faacfd56fd420824f
parent722b65a2f0eb80522fb6d019650881d75cf9f63f (diff)
Don't suggest to pass classes with deleted copy ctor by value
BUG: 403088
-rw-r--r--src/TypeUtils.cpp3
-rw-r--r--tests/function-args-by-value/main.cpp12
-rw-r--r--tests/function-args-by-value/main.cpp_fixed.cpp.expected12
3 files changed, 26 insertions, 1 deletions
diff --git a/src/TypeUtils.cpp b/src/TypeUtils.cpp
index 87cbbcb6..75b092e9 100644
--- a/src/TypeUtils.cpp
+++ b/src/TypeUtils.cpp
@@ -52,7 +52,8 @@ bool TypeUtils::classifyQualType(const ClazyContext *context, const VarDecl *var
classif.size_of_T = context->astContext.getTypeSize(qualType) / 8;
classif.isBig = classif.size_of_T > 16;
CXXRecordDecl *recordDecl = paramType->getAsCXXRecordDecl();
- classif.isNonTriviallyCopyable = recordDecl && (recordDecl->hasNonTrivialCopyConstructor() || recordDecl->hasNonTrivialDestructor());
+ CXXMethodDecl *copyCtor = recordDecl ? Utils::copyCtor(recordDecl) : nullptr;
+ classif.isNonTriviallyCopyable = recordDecl && (recordDecl->hasNonTrivialCopyConstructor() || recordDecl->hasNonTrivialDestructor() || (copyCtor && copyCtor->isDeleted()));
classif.isReference = varDecl->getType()->isLValueReferenceType();
classif.isConst = qualType.isConstQualified();
diff --git a/tests/function-args-by-value/main.cpp b/tests/function-args-by-value/main.cpp
index b8e85085..bd93208c 100644
--- a/tests/function-args-by-value/main.cpp
+++ b/tests/function-args-by-value/main.cpp
@@ -233,3 +233,15 @@ public:
void virtualMethod2(const Trivial &) {}; // OK
void nonVirtualMethod(const Trivial &) {}; // Warn
};
+
+
+// bug #403088
+void func(const std::atomic<int> &a) {} // Ok, since it's not trivially-copyable
+
+// generalization of bug #403088
+struct DeletedCopyCtor {
+ DeletedCopyCtor(const DeletedCopyCtor &) = delete;
+ int v;
+};
+
+void func(const DeletedCopyCtor &a) {}
diff --git a/tests/function-args-by-value/main.cpp_fixed.cpp.expected b/tests/function-args-by-value/main.cpp_fixed.cpp.expected
index a76ae555..0fb5be32 100644
--- a/tests/function-args-by-value/main.cpp_fixed.cpp.expected
+++ b/tests/function-args-by-value/main.cpp_fixed.cpp.expected
@@ -233,3 +233,15 @@ public:
void virtualMethod2(const Trivial &) {}; // OK
void nonVirtualMethod(Trivial ) {}; // Warn
};
+
+
+// bug #403088
+void func(const std::atomic<int> &a) {} // Ok, since it's not trivially-copyable
+
+// generalization of bug #403088
+struct DeletedCopyCtor {
+ DeletedCopyCtor(const DeletedCopyCtor &) = delete;
+ int v;
+};
+
+void func(const DeletedCopyCtor &a) {}