Skip to content

Commit e817e4f

Browse files
committed
STYLE: Use default member initialization
Converts a default constructor’s member initializers into the new default member initializers in C++11. Other member initializers that match the default member initializer are removed. This can reduce repeated code or allow use of ‘= default’. SRCDIR=/Users/johnsonhj/src/jsoncpp/ #My local SRC BLDDIR=/Users/johnsonhj/src/jsoncpp/cmake-build-debug/ #My local BLD cd /Users/johnsonhj/src/jsoncpp/cmake-build-debug/ run-clang-tidy.py -extra-arg=-D__clang__ -checks=-*,modernize-use-default-member-init -header-filter=.* -fix
1 parent b5093e8 commit e817e4f

File tree

11 files changed

+49
-52
lines changed

11 files changed

+49
-52
lines changed

include/json/features.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,17 @@ class JSON_API Features {
4141
Features();
4242

4343
/// \c true if comments are allowed. Default: \c true.
44-
bool allowComments_;
44+
bool allowComments_{true};
4545

4646
/// \c true if root must be either an array or an object value. Default: \c
4747
/// false.
48-
bool strictRoot_;
48+
bool strictRoot_{false};
4949

5050
/// \c true if dropped null placeholders are allowed. Default: \c false.
51-
bool allowDroppedNullPlaceholders_;
51+
bool allowDroppedNullPlaceholders_{false};
5252

5353
/// \c true if numeric object key are allowed. Default: \c false.
54-
bool allowNumericKeys_;
54+
bool allowNumericKeys_{false};
5555
};
5656

5757
} // namespace Json

include/json/reader.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,14 @@ class JSON_API Reader {
242242
Nodes nodes_;
243243
Errors errors_;
244244
JSONCPP_STRING document_;
245-
Location begin_;
246-
Location end_;
247-
Location current_;
248-
Location lastValueEnd_;
249-
Value* lastValue_;
245+
Location begin_{};
246+
Location end_{};
247+
Location current_{};
248+
Location lastValueEnd_{};
249+
Value* lastValue_{};
250250
JSONCPP_STRING commentsBefore_;
251251
Features features_;
252-
bool collectComments_;
252+
bool collectComments_{};
253253
}; // Reader
254254

255255
/** Interface for reading JSON from a char array.

include/json/value.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ Json::Value obj_value(Json::objectValue); // {}
630630

631631
void setComment(const char* text, size_t len);
632632

633-
char* comment_;
633+
char* comment_{nullptr};
634634
};
635635

636636
// struct MemberNamesTransform
@@ -678,8 +678,8 @@ class JSON_API PathArgument {
678678
private:
679679
enum Kind { kindNone = 0, kindIndex, kindKey };
680680
JSONCPP_STRING key_;
681-
ArrayIndex index_;
682-
Kind kind_;
681+
ArrayIndex index_{};
682+
Kind kind_{kindNone};
683683
};
684684

685685
/** \brief Experimental and untested: represents a "path" to access a node.
@@ -780,7 +780,7 @@ class JSON_API ValueIteratorBase {
780780
private:
781781
Value::ObjectValues::iterator current_;
782782
// Indicates that iterator is for a null value.
783-
bool isNull_;
783+
bool isNull_{true};
784784

785785
public:
786786
// For some reason, BORLAND needs these at the end, rather

include/json/writer.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,9 @@ class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API FastWriter
189189
void writeValue(const Value& value);
190190

191191
JSONCPP_STRING document_;
192-
bool yamlCompatibilityEnabled_;
193-
bool dropNullPlaceholders_;
194-
bool omitEndingLineFeed_;
192+
bool yamlCompatibilityEnabled_{false};
193+
bool dropNullPlaceholders_{false};
194+
bool omitEndingLineFeed_{false};
195195
};
196196
#if defined(_MSC_VER)
197197
#pragma warning(pop)
@@ -257,9 +257,9 @@ class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API
257257
ChildValues childValues_;
258258
JSONCPP_STRING document_;
259259
JSONCPP_STRING indentString_;
260-
unsigned int rightMargin_;
261-
unsigned int indentSize_;
262-
bool addChildValues_;
260+
unsigned int rightMargin_{74};
261+
unsigned int indentSize_{3};
262+
bool addChildValues_{false};
263263
};
264264
#if defined(_MSC_VER)
265265
#pragma warning(pop)
@@ -331,7 +331,7 @@ class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API
331331
ChildValues childValues_;
332332
JSONCPP_OSTREAM* document_;
333333
JSONCPP_STRING indentString_;
334-
unsigned int rightMargin_;
334+
unsigned int rightMargin_{74};
335335
JSONCPP_STRING indentation_;
336336
bool addChildValues_ : 1;
337337
bool indented_ : 1;

src/lib_json/json_reader.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ typedef std::auto_ptr<CharReader> CharReaderPtr;
6060
// ////////////////////////////////
6161

6262
Features::Features()
63-
: allowComments_(true), strictRoot_(false),
64-
allowDroppedNullPlaceholders_(false), allowNumericKeys_(false) {}
63+
{}
6564

6665
Features Features::all() { return {}; }
6766

src/lib_json/json_value.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ JSONCPP_NORETURN void throwLogicError(JSONCPP_STRING const& msg) {
233233
// //////////////////////////////////////////////////////////////////
234234
// //////////////////////////////////////////////////////////////////
235235

236-
Value::CommentInfo::CommentInfo() : comment_(nullptr) {}
236+
Value::CommentInfo::CommentInfo() {}
237237

238238
Value::CommentInfo::~CommentInfo() {
239239
if (comment_)
@@ -1575,7 +1575,7 @@ Value::iterator Value::end() {
15751575
// class PathArgument
15761576
// //////////////////////////////////////////////////////////////////
15771577

1578-
PathArgument::PathArgument() : key_(), index_(), kind_(kindNone) {}
1578+
PathArgument::PathArgument() : key_() {}
15791579

15801580
PathArgument::PathArgument(ArrayIndex index)
15811581
: key_(), index_(index), kind_(kindIndex) {}

src/lib_json/json_valueiterator.inl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace Json {
1616
// //////////////////////////////////////////////////////////////////
1717

1818
ValueIteratorBase::ValueIteratorBase()
19-
: current_(), isNull_(true) {
19+
: current_() {
2020
}
2121

2222
ValueIteratorBase::ValueIteratorBase(

src/lib_json/json_writer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,8 @@ Writer::~Writer() {}
352352
// //////////////////////////////////////////////////////////////////
353353

354354
FastWriter::FastWriter()
355-
: yamlCompatibilityEnabled_(false), dropNullPlaceholders_(false),
356-
omitEndingLineFeed_(false) {}
355+
356+
{}
357357

358358
void FastWriter::enableYAMLCompatibility() { yamlCompatibilityEnabled_ = true; }
359359

@@ -428,7 +428,7 @@ void FastWriter::writeValue(const Value& value) {
428428
// //////////////////////////////////////////////////////////////////
429429

430430
StyledWriter::StyledWriter()
431-
: rightMargin_(74), indentSize_(3), addChildValues_(false) {}
431+
{}
432432

433433
JSONCPP_STRING StyledWriter::write(const Value& root) {
434434
document_.clear();

src/test_lib_json/jsontest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ namespace JsonTest {
7474
// //////////////////////////////////////////////////////////////////
7575

7676
TestResult::TestResult()
77-
: predicateId_(1), lastUsedPredicateId_(0), messageTarget_(nullptr) {
77+
{
7878
// The root predicate has id 0
7979
rootPredicateNode_.id_ = 0;
8080
rootPredicateNode_.next_ = nullptr;
@@ -205,7 +205,7 @@ TestResult& TestResult::operator<<(bool value) {
205205
// class TestCase
206206
// //////////////////////////////////////////////////////////////////
207207

208-
TestCase::TestCase() : result_(nullptr) {}
208+
TestCase::TestCase() {}
209209

210210
TestCase::~TestCase() {}
211211

src/test_lib_json/jsontest.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class TestResult {
6060
/// Not encapsulated to prevent step into when debugging failed assertions
6161
/// Incremented by one on assertion predicate entry, decreased by one
6262
/// by addPredicateContext().
63-
PredicateContext::Id predicateId_;
63+
PredicateContext::Id predicateId_{1};
6464

6565
/// \internal Implementation detail for predicate macros
6666
PredicateContext* predicateStackTail_;
@@ -109,9 +109,9 @@ class TestResult {
109109
Failures failures_;
110110
JSONCPP_STRING name_;
111111
PredicateContext rootPredicateNode_;
112-
PredicateContext::Id lastUsedPredicateId_;
112+
PredicateContext::Id lastUsedPredicateId_{0};
113113
/// Failure which is the target of the messages added using operator <<
114-
Failure* messageTarget_;
114+
Failure* messageTarget_{nullptr};
115115
};
116116

117117
class TestCase {
@@ -125,7 +125,7 @@ class TestCase {
125125
virtual const char* testName() const = 0;
126126

127127
protected:
128-
TestResult* result_;
128+
TestResult* result_{nullptr};
129129

130130
private:
131131
virtual void runTestCase() = 0;

src/test_lib_json/main.cpp

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,19 @@ struct ValueTest : JsonTest::TestCase {
8282
/// Initialize all checks to \c false by default.
8383
IsCheck();
8484

85-
bool isObject_;
86-
bool isArray_;
87-
bool isBool_;
88-
bool isString_;
89-
bool isNull_;
90-
91-
bool isInt_;
92-
bool isInt64_;
93-
bool isUInt_;
94-
bool isUInt64_;
95-
bool isIntegral_;
96-
bool isDouble_;
97-
bool isNumeric_;
85+
bool isObject_{false};
86+
bool isArray_{false};
87+
bool isBool_{false};
88+
bool isString_{false};
89+
bool isNull_{false};
90+
91+
bool isInt_{false};
92+
bool isInt64_{false};
93+
bool isUInt_{false};
94+
bool isUInt64_{false};
95+
bool isIntegral_{false};
96+
bool isDouble_{false};
97+
bool isNumeric_{false};
9898
};
9999

100100
void checkConstMemberCount(const Json::Value& value,
@@ -1331,10 +1331,8 @@ void ValueTest::checkMemberCount(Json::Value& value,
13311331
}
13321332

13331333
ValueTest::IsCheck::IsCheck()
1334-
: isObject_(false), isArray_(false), isBool_(false), isString_(false),
1335-
isNull_(false), isInt_(false), isInt64_(false), isUInt_(false),
1336-
isUInt64_(false), isIntegral_(false), isDouble_(false),
1337-
isNumeric_(false) {}
1334+
1335+
{}
13381336

13391337
void ValueTest::checkIs(const Json::Value& value, const IsCheck& check) {
13401338
JSONTEST_ASSERT_EQUAL(check.isObject_, value.isObject());

0 commit comments

Comments
 (0)