diff options
author | Felix Berger <flx@google.com> | 2016-02-15 04:27:56 +0000 |
---|---|---|
committer | Felix Berger <flx@google.com> | 2016-02-15 04:27:56 +0000 |
commit | 72a592a5af8030e2026f38a726eb926709941611 (patch) | |
tree | 1c60cb16a6a82c81eaf2051602dd2e92555abe56 /clang-tools-extra/test/clang-tidy/cppcoreguidelines-pro-type-member-init-cxx98.cpp | |
parent | db7a405002a0729de1a5c513726195f9bcac5d64 (diff) |
[clang-tidy] ClangTidy check to flag uninitialized builtin and pointer fields.
Summary:
This patch is a continuation of http://reviews.llvm.org/D10553 by Jonathan B Coe.
The main additions are:
1. For C++11 the check suggests in-class field initialization as fix. This
makes the fields future proof towards the addition of new constructors.
2 For older language versions the fields are added in the right position
in the initializer list with more tests.
3. User documentation.
Reviewers: alexfh, jbcoe
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D16517
Diffstat (limited to 'clang-tools-extra/test/clang-tidy/cppcoreguidelines-pro-type-member-init-cxx98.cpp')
-rw-r--r-- | clang-tools-extra/test/clang-tidy/cppcoreguidelines-pro-type-member-init-cxx98.cpp | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/clang-tools-extra/test/clang-tidy/cppcoreguidelines-pro-type-member-init-cxx98.cpp b/clang-tools-extra/test/clang-tidy/cppcoreguidelines-pro-type-member-init-cxx98.cpp new file mode 100644 index 00000000000..164ab56637e --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/cppcoreguidelines-pro-type-member-init-cxx98.cpp @@ -0,0 +1,67 @@ +// RUN: %check_clang_tidy %s cppcoreguidelines-pro-type-member-init %t -- -- -std=c++98 + +struct PositiveFieldBeforeConstructor { + int F; + PositiveFieldBeforeConstructor() /* some comment */ {} + // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these built-in/pointer fields: F + // CHECK-FIXES: PositiveFieldBeforeConstructor() : F() /* some comment */ {} +}; + +struct PositiveFieldAfterConstructor { + PositiveFieldAfterConstructor() {} + // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these built-in/pointer fields: F, G, H + // CHECK-FIXES: PositiveFieldAfterConstructor() : F(), G(), H() {} + int F; + bool G /* with comment */; + int *H; + PositiveFieldBeforeConstructor IgnoredField; +}; + +struct PositiveSeparateDefinition { + PositiveSeparateDefinition(); + int F; +}; + +PositiveSeparateDefinition::PositiveSeparateDefinition() {} +// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: constructor does not initialize these built-in/pointer fields: F +// CHECK-FIXES: PositiveSeparateDefinition::PositiveSeparateDefinition() : F() {} + +struct PositiveMixedFieldOrder { + PositiveMixedFieldOrder() : /* some comment */ J(0), L(0), M(0) {} + // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these built-in/pointer fields: I, K, N + // CHECK-FIXES: PositiveMixedFieldOrder() : I(), /* some comment */ J(0), K(), L(0), M(0), N() {} + int I; + int J; + int K; + int L; + int M; + int N; +}; + +struct PositiveAfterBaseInitializer : public PositiveMixedFieldOrder { + PositiveAfterBaseInitializer() : PositiveMixedFieldOrder() {} + // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these built-in/pointer fields: F + // CHECK-FIXES: PositiveAfterBaseInitializer() : PositiveMixedFieldOrder(), F() {} + int F; +}; + +struct NegativeFieldInitialized { + int F; + + NegativeFieldInitialized() : F() {} +}; + +struct NegativeFieldInitializedInDefinition { + int F; + + NegativeFieldInitializedInDefinition(); +}; + +NegativeFieldInitializedInDefinition::NegativeFieldInitializedInDefinition() : F() {} + +struct NegativeInitializedInBody { + NegativeInitializedInBody() { I = 0; } + int I; +}; + + |