summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/test/clang-tidy/modernize-use-default.cpp
diff options
context:
space:
mode:
authorAngel Garcia Gomez <angelgarcia@google.com>2015-10-21 12:58:15 +0000
committerAngel Garcia Gomez <angelgarcia@google.com>2015-10-21 12:58:15 +0000
commit8dedeb0230c589ca121098f8051a35eb5fb53848 (patch)
tree3f77020d05c442b64ee9b064d08d0a71f1ff8ec9 /clang-tools-extra/test/clang-tidy/modernize-use-default.cpp
parentbaf54a8ad5710d54bc6cc8fd2e7f1fcfabc9c503 (diff)
downloadbcm5719-llvm-8dedeb0230c589ca121098f8051a35eb5fb53848.tar.gz
bcm5719-llvm-8dedeb0230c589ca121098f8051a35eb5fb53848.zip
Add modernize-use-default check to clang-tidy.
Summary: Add a check that replaces empty bodies of special member functions with '= default;'. For now, it is only implemented for the default constructor and the destructor, which are the easier cases. The copy-constructor and the copy-assignment operator cases will be implemented later. I applied this check to the llvm code base and found 627 warnings (385 in llvm, 9 in compiler-rt, 220 in clang and 13 in clang-tools-extra). Applying the fixes didn't break any build or test, it only caused a -Wpedantic warning in lib/Target/Mips/MipsOptionRecord.h:33 becaused it replaced virtual ~MipsOptionRecord(){}; to virtual ~MipsOptionRecord()= default;; Reviewers: klimek Subscribers: george.burgess.iv, Eugene.Zelenko, alexfh, cfe-commits Differential Revision: http://reviews.llvm.org/D13871 llvm-svn: 250897
Diffstat (limited to 'clang-tools-extra/test/clang-tidy/modernize-use-default.cpp')
-rw-r--r--clang-tools-extra/test/clang-tidy/modernize-use-default.cpp137
1 files changed, 137 insertions, 0 deletions
diff --git a/clang-tools-extra/test/clang-tidy/modernize-use-default.cpp b/clang-tools-extra/test/clang-tidy/modernize-use-default.cpp
new file mode 100644
index 00000000000..9e4a5513336
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/modernize-use-default.cpp
@@ -0,0 +1,137 @@
+// RUN: %python %S/check_clang_tidy.py %s modernize-use-default %t
+
+class A {
+public:
+ A();
+ ~A();
+};
+
+A::A() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use '= default' to define a trivial default constructor [modernize-use-default]
+// CHECK-FIXES: A::A() = default;
+A::~A() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use '= default' to define a trivial destructor [modernize-use-default]
+// CHECK-FIXES: A::~A() = default;
+
+// Inline definitions.
+class B {
+public:
+ B() {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default'
+ // CHECK-FIXES: B() = default;
+ ~B() {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default'
+ // CHECK-FIXES: ~B() = default;
+};
+
+void f();
+
+class C {
+public:
+ // Non-empty constructor body.
+ C() { f(); }
+ // Non-empty destructor body.
+ ~C() { f(); }
+};
+
+class D {
+public:
+ // Constructor with initializer.
+ D() : Field(5) {}
+ // Constructor with arguments.
+ D(int Arg1, int Arg2) {}
+ int Field;
+};
+
+// Private constructor/destructor.
+class E {
+ E() {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default'
+ // CHECK-FIXES: E() = default;
+ ~E() {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default'
+ // CHECK-FIXES: ~E() = default;
+};
+
+// struct.
+struct F {
+ F() {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default'
+ // CHECK-FIXES: F() = default;
+ ~F() {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default'
+ // CHECK-FIXES: F() = default;
+};
+
+// Deleted constructor/destructor.
+class G {
+public:
+ G() = delete;
+ ~G() = delete;
+};
+
+// Do not remove other keywords.
+class H {
+public:
+ explicit H() {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default'
+ // CHECK-FIXES: explicit H() = default;
+ virtual ~H() {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default'
+ // CHECK-FIXES: virtual ~H() = default;
+};
+
+// Nested class.
+struct I {
+ struct II {
+ II() {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use '= default'
+ // CHECK-FIXES: II() = default;
+ ~II() {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use '= default'
+ // CHECK-FIXES: ~II() = default;
+ };
+ int Int;
+};
+
+// Class template.
+template <class T>
+class J {
+public:
+ J() {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default'
+ // CHECK-FIXES: J() = default;
+ ~J() {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default'
+ // CHECK-FIXES: ~J() = default;
+};
+
+// Non user-provided constructor/destructor.
+struct K {
+ int Int;
+};
+void g() {
+ K *PtrK = new K();
+ PtrK->~K();
+ delete PtrK;
+}
+
+// Already using default.
+struct L {
+ L() = default;
+ ~L() = default;
+};
+struct M {
+ M();
+ ~M();
+};
+M::M() = default;
+M::~M() = default;
+
+// Delegating constructor and overriden destructor.
+struct N : H {
+ N() : H() {}
+ ~N() override {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default'
+ // CHECK-FIXES: ~N() override = default;
+};
OpenPOWER on IntegriCloud