summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/test
diff options
context:
space:
mode:
authorMitchell Balan <mitchell@stellarscience.com>2019-11-19 10:57:16 -0500
committerMitchell Balan <mitchell@stellarscience.com>2019-11-19 10:59:21 -0500
commit980653621ef563df41f1d09a1ac8c58708f79930 (patch)
treec60a9bcc6862c6937ff5595ba488e41e22c15c5e /clang-tools-extra/test
parent39de82ecc9c2e461e1318ed9926286a1eed2be3f (diff)
downloadbcm5719-llvm-980653621ef563df41f1d09a1ac8c58708f79930.tar.gz
bcm5719-llvm-980653621ef563df41f1d09a1ac8c58708f79930.zip
[clang-tidy] Give readability-redundant-member-init an option IgnoreBaseInCopyConstructors to avoid breaking code with gcc -Werror=extra
Summary: readability-redundant-member-init removes redundant / unnecessary member and base class initialization. Unfortunately for the specific case of a copy constructor's initialization of a base class, gcc at strict warning levels warns if "base class is not initialized in the copy constructor of a derived class". This patch adds an option `IgnoreBaseInCopyConstructors` defaulting to 0 (thus maintaining current behavior by default) to skip the specific case of removal of redundant base class initialization in the copy constructor. Enabling this option enables the resulting code to continue to compile successfully under `gcc -Werror=extra`. New test cases `WithCopyConstructor1` and `WithCopyConstructor2` in clang-tools-extra/test/clang-tidy/readability-redundant-member-init.cpp show that it removes redundant members even from copy constructors. Reviewers: malcolm.parsons, alexfh, hokein, aaron.ballman, lebedev.ri Patch by: poelmanc Subscribers: mgehre, lebedev.ri, cfe-commits Tags: #clang, #clang-tools-extra Differential revision: https://reviews.llvm.org/D69145
Diffstat (limited to 'clang-tools-extra/test')
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/readability-redundant-member-init.cpp35
1 files changed, 34 insertions, 1 deletions
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability-redundant-member-init.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability-redundant-member-init.cpp
index 90b52fd1a48..0f8c028aabb 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability-redundant-member-init.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability-redundant-member-init.cpp
@@ -1,4 +1,8 @@
-// RUN: %check_clang_tidy %s readability-redundant-member-init %t
+// RUN: %check_clang_tidy %s readability-redundant-member-init %t \
+// RUN: -config="{CheckOptions: \
+// RUN: [{key: readability-redundant-member-init.IgnoreBaseInCopyConstructors, \
+// RUN: value: 1}] \
+// RUN: }"
struct S {
S() = default;
@@ -116,6 +120,35 @@ struct F9 {
};
};
+// struct whose inline copy constructor default-initializes its base class
+struct WithCopyConstructor1 : public T {
+ WithCopyConstructor1(const WithCopyConstructor1& other) : T(),
+ f(),
+ g()
+ {}
+ S f, g;
+};
+// No warning in copy constructor about T since IgnoreBaseInCopyConstructors=1
+// CHECK-MESSAGES: :[[@LINE-6]]:5: warning: initializer for member 'f' is redundant
+// CHECK-MESSAGES: :[[@LINE-6]]:5: warning: initializer for member 'g' is redundant
+// CHECK-FIXES: WithCopyConstructor1(const WithCopyConstructor1& other) : T()
+// CHECK-NEXT:
+// CHECK-NEXT:
+// CHECK-NEXT: {}
+
+// struct whose copy constructor default-initializes its base class
+struct WithCopyConstructor2 : public T {
+ WithCopyConstructor2(const WithCopyConstructor2& other);
+ S a;
+};
+WithCopyConstructor2::WithCopyConstructor2(const WithCopyConstructor2& other)
+ : T(), a()
+{}
+// No warning in copy constructor about T since IgnoreBaseInCopyConstructors=1
+// CHECK-MESSAGES: :[[@LINE-3]]:10: warning: initializer for member 'a' is redundant
+// CHECK-FIXES: {{^}} : T() {{$}}
+// CHECK-NEXT: {}
+
// Initializer not written
struct NF1 {
NF1() {}
OpenPOWER on IntegriCloud