summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/test/clang-tidy/misc-assign-operator-signature.cpp
diff options
context:
space:
mode:
authorSamuel Benzaquen <sbenza@google.com>2015-02-09 17:50:40 +0000
committerSamuel Benzaquen <sbenza@google.com>2015-02-09 17:50:40 +0000
commitb5cbe0100f4e29f67999618622f3786ff98cd533 (patch)
treea9b840fa4468d56657f79d25eff304b44fd37d38 /clang-tools-extra/test/clang-tidy/misc-assign-operator-signature.cpp
parent3f308ab127e068f6f4f43afa8f09d971b7bc6d83 (diff)
downloadbcm5719-llvm-b5cbe0100f4e29f67999618622f3786ff98cd533.tar.gz
bcm5719-llvm-b5cbe0100f4e29f67999618622f3786ff98cd533.zip
Verify assign operator signatures.
Summary: Warn when the return type of assign operators is not Class&. Reviewers: alexfh Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D6667 llvm-svn: 228583
Diffstat (limited to 'clang-tools-extra/test/clang-tidy/misc-assign-operator-signature.cpp')
-rw-r--r--clang-tools-extra/test/clang-tidy/misc-assign-operator-signature.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/clang-tools-extra/test/clang-tidy/misc-assign-operator-signature.cpp b/clang-tools-extra/test/clang-tidy/misc-assign-operator-signature.cpp
new file mode 100644
index 00000000000..bdeca538954
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/misc-assign-operator-signature.cpp
@@ -0,0 +1,52 @@
+// RUN: $(dirname %s)/check_clang_tidy.sh %s misc-assign-operator-signature %t
+// REQUIRES: shell
+
+struct Good {
+ Good& operator=(const Good&);
+ Good& operator=(Good&&);
+
+ // Assign from other types is fine too.
+ Good& operator=(int);
+};
+
+struct AlsoGood {
+ // By value is also fine.
+ AlsoGood& operator=(AlsoGood);
+};
+
+struct BadReturn {
+ void operator=(const BadReturn&);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: operator=() should return 'BadReturn&' [misc-assign-operator-signature]
+ const BadReturn& operator=(BadReturn&&);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: operator=() should return 'Bad
+};
+struct BadReturn2 {
+ BadReturn2&& operator=(const BadReturn2&);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: operator=() should return 'Bad
+ int operator=(BadReturn2&&);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: operator=() should return 'Bad
+};
+
+struct BadArgument {
+ BadArgument& operator=(BadArgument&);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: operator=() should take 'BadArgument const&', 'BadArgument&&' or 'BadArgument'
+ BadArgument& operator=(const BadArgument&&);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: operator=() should take 'BadAr
+};
+
+struct BadModifier {
+ BadModifier& operator=(const BadModifier&) const;
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: operator=() should not be marked 'const'
+};
+
+struct Deleted {
+ // We don't check the return value of deleted operators.
+ void operator=(const Deleted&) = delete;
+ void operator=(Deleted&&) = delete;
+};
+
+class Private {
+ // We don't check the return value of private operators.
+ // Pre-C++11 way of disabling assignment.
+ void operator=(const Private &);
+};
OpenPOWER on IntegriCloud