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
This commit is contained in:
Hans Johnson 2019-01-14 17:09:22 -06:00 committed by Hans Johnson
parent b5093e8122
commit e817e4fc25
11 changed files with 48 additions and 51 deletions

View File

@ -41,17 +41,17 @@ public:
Features(); Features();
/// \c true if comments are allowed. Default: \c true. /// \c true if comments are allowed. Default: \c true.
bool allowComments_; bool allowComments_{true};
/// \c true if root must be either an array or an object value. Default: \c /// \c true if root must be either an array or an object value. Default: \c
/// false. /// false.
bool strictRoot_; bool strictRoot_{false};
/// \c true if dropped null placeholders are allowed. Default: \c false. /// \c true if dropped null placeholders are allowed. Default: \c false.
bool allowDroppedNullPlaceholders_; bool allowDroppedNullPlaceholders_{false};
/// \c true if numeric object key are allowed. Default: \c false. /// \c true if numeric object key are allowed. Default: \c false.
bool allowNumericKeys_; bool allowNumericKeys_{false};
}; };
} // namespace Json } // namespace Json

View File

@ -242,14 +242,14 @@ private:
Nodes nodes_; Nodes nodes_;
Errors errors_; Errors errors_;
JSONCPP_STRING document_; JSONCPP_STRING document_;
Location begin_; Location begin_{};
Location end_; Location end_{};
Location current_; Location current_{};
Location lastValueEnd_; Location lastValueEnd_{};
Value* lastValue_; Value* lastValue_{};
JSONCPP_STRING commentsBefore_; JSONCPP_STRING commentsBefore_;
Features features_; Features features_;
bool collectComments_; bool collectComments_{};
}; // Reader }; // Reader
/** Interface for reading JSON from a char array. /** Interface for reading JSON from a char array.

View File

@ -630,7 +630,7 @@ private:
void setComment(const char* text, size_t len); void setComment(const char* text, size_t len);
char* comment_; char* comment_{nullptr};
}; };
// struct MemberNamesTransform // struct MemberNamesTransform
@ -678,8 +678,8 @@ public:
private: private:
enum Kind { kindNone = 0, kindIndex, kindKey }; enum Kind { kindNone = 0, kindIndex, kindKey };
JSONCPP_STRING key_; JSONCPP_STRING key_;
ArrayIndex index_; ArrayIndex index_{};
Kind kind_; Kind kind_{kindNone};
}; };
/** \brief Experimental and untested: represents a "path" to access a node. /** \brief Experimental and untested: represents a "path" to access a node.
@ -780,7 +780,7 @@ protected:
private: private:
Value::ObjectValues::iterator current_; Value::ObjectValues::iterator current_;
// Indicates that iterator is for a null value. // Indicates that iterator is for a null value.
bool isNull_; bool isNull_{true};
public: public:
// For some reason, BORLAND needs these at the end, rather // For some reason, BORLAND needs these at the end, rather

View File

@ -189,9 +189,9 @@ private:
void writeValue(const Value& value); void writeValue(const Value& value);
JSONCPP_STRING document_; JSONCPP_STRING document_;
bool yamlCompatibilityEnabled_; bool yamlCompatibilityEnabled_{false};
bool dropNullPlaceholders_; bool dropNullPlaceholders_{false};
bool omitEndingLineFeed_; bool omitEndingLineFeed_{false};
}; };
#if defined(_MSC_VER) #if defined(_MSC_VER)
#pragma warning(pop) #pragma warning(pop)
@ -257,9 +257,9 @@ private:
ChildValues childValues_; ChildValues childValues_;
JSONCPP_STRING document_; JSONCPP_STRING document_;
JSONCPP_STRING indentString_; JSONCPP_STRING indentString_;
unsigned int rightMargin_; unsigned int rightMargin_{74};
unsigned int indentSize_; unsigned int indentSize_{3};
bool addChildValues_; bool addChildValues_{false};
}; };
#if defined(_MSC_VER) #if defined(_MSC_VER)
#pragma warning(pop) #pragma warning(pop)
@ -331,7 +331,7 @@ private:
ChildValues childValues_; ChildValues childValues_;
JSONCPP_OSTREAM* document_; JSONCPP_OSTREAM* document_;
JSONCPP_STRING indentString_; JSONCPP_STRING indentString_;
unsigned int rightMargin_; unsigned int rightMargin_{74};
JSONCPP_STRING indentation_; JSONCPP_STRING indentation_;
bool addChildValues_ : 1; bool addChildValues_ : 1;
bool indented_ : 1; bool indented_ : 1;

View File

@ -60,8 +60,7 @@ typedef std::auto_ptr<CharReader> CharReaderPtr;
// //////////////////////////////// // ////////////////////////////////
Features::Features() Features::Features()
: allowComments_(true), strictRoot_(false), {}
allowDroppedNullPlaceholders_(false), allowNumericKeys_(false) {}
Features Features::all() { return {}; } Features Features::all() { return {}; }

View File

@ -233,7 +233,7 @@ JSONCPP_NORETURN void throwLogicError(JSONCPP_STRING const& msg) {
// ////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////
// ////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////
Value::CommentInfo::CommentInfo() : comment_(nullptr) {} Value::CommentInfo::CommentInfo() {}
Value::CommentInfo::~CommentInfo() { Value::CommentInfo::~CommentInfo() {
if (comment_) if (comment_)
@ -1575,7 +1575,7 @@ Value::iterator Value::end() {
// class PathArgument // class PathArgument
// ////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////
PathArgument::PathArgument() : key_(), index_(), kind_(kindNone) {} PathArgument::PathArgument() : key_() {}
PathArgument::PathArgument(ArrayIndex index) PathArgument::PathArgument(ArrayIndex index)
: key_(), index_(index), kind_(kindIndex) {} : key_(), index_(index), kind_(kindIndex) {}

View File

@ -16,7 +16,7 @@ namespace Json {
// ////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////
ValueIteratorBase::ValueIteratorBase() ValueIteratorBase::ValueIteratorBase()
: current_(), isNull_(true) { : current_() {
} }
ValueIteratorBase::ValueIteratorBase( ValueIteratorBase::ValueIteratorBase(

View File

@ -352,8 +352,8 @@ Writer::~Writer() {}
// ////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////
FastWriter::FastWriter() FastWriter::FastWriter()
: yamlCompatibilityEnabled_(false), dropNullPlaceholders_(false),
omitEndingLineFeed_(false) {} {}
void FastWriter::enableYAMLCompatibility() { yamlCompatibilityEnabled_ = true; } void FastWriter::enableYAMLCompatibility() { yamlCompatibilityEnabled_ = true; }
@ -428,7 +428,7 @@ void FastWriter::writeValue(const Value& value) {
// ////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////
StyledWriter::StyledWriter() StyledWriter::StyledWriter()
: rightMargin_(74), indentSize_(3), addChildValues_(false) {} {}
JSONCPP_STRING StyledWriter::write(const Value& root) { JSONCPP_STRING StyledWriter::write(const Value& root) {
document_.clear(); document_.clear();

View File

@ -74,7 +74,7 @@ namespace JsonTest {
// ////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////
TestResult::TestResult() TestResult::TestResult()
: predicateId_(1), lastUsedPredicateId_(0), messageTarget_(nullptr) { {
// The root predicate has id 0 // The root predicate has id 0
rootPredicateNode_.id_ = 0; rootPredicateNode_.id_ = 0;
rootPredicateNode_.next_ = nullptr; rootPredicateNode_.next_ = nullptr;
@ -205,7 +205,7 @@ TestResult& TestResult::operator<<(bool value) {
// class TestCase // class TestCase
// ////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////
TestCase::TestCase() : result_(nullptr) {} TestCase::TestCase() {}
TestCase::~TestCase() {} TestCase::~TestCase() {}

View File

@ -60,7 +60,7 @@ public:
/// Not encapsulated to prevent step into when debugging failed assertions /// Not encapsulated to prevent step into when debugging failed assertions
/// Incremented by one on assertion predicate entry, decreased by one /// Incremented by one on assertion predicate entry, decreased by one
/// by addPredicateContext(). /// by addPredicateContext().
PredicateContext::Id predicateId_; PredicateContext::Id predicateId_{1};
/// \internal Implementation detail for predicate macros /// \internal Implementation detail for predicate macros
PredicateContext* predicateStackTail_; PredicateContext* predicateStackTail_;
@ -109,9 +109,9 @@ private:
Failures failures_; Failures failures_;
JSONCPP_STRING name_; JSONCPP_STRING name_;
PredicateContext rootPredicateNode_; PredicateContext rootPredicateNode_;
PredicateContext::Id lastUsedPredicateId_; PredicateContext::Id lastUsedPredicateId_{0};
/// Failure which is the target of the messages added using operator << /// Failure which is the target of the messages added using operator <<
Failure* messageTarget_; Failure* messageTarget_{nullptr};
}; };
class TestCase { class TestCase {
@ -125,7 +125,7 @@ public:
virtual const char* testName() const = 0; virtual const char* testName() const = 0;
protected: protected:
TestResult* result_; TestResult* result_{nullptr};
private: private:
virtual void runTestCase() = 0; virtual void runTestCase() = 0;

View File

@ -82,19 +82,19 @@ struct ValueTest : JsonTest::TestCase {
/// Initialize all checks to \c false by default. /// Initialize all checks to \c false by default.
IsCheck(); IsCheck();
bool isObject_; bool isObject_{false};
bool isArray_; bool isArray_{false};
bool isBool_; bool isBool_{false};
bool isString_; bool isString_{false};
bool isNull_; bool isNull_{false};
bool isInt_; bool isInt_{false};
bool isInt64_; bool isInt64_{false};
bool isUInt_; bool isUInt_{false};
bool isUInt64_; bool isUInt64_{false};
bool isIntegral_; bool isIntegral_{false};
bool isDouble_; bool isDouble_{false};
bool isNumeric_; bool isNumeric_{false};
}; };
void checkConstMemberCount(const Json::Value& value, void checkConstMemberCount(const Json::Value& value,
@ -1331,10 +1331,8 @@ void ValueTest::checkMemberCount(Json::Value& value,
} }
ValueTest::IsCheck::IsCheck() ValueTest::IsCheck::IsCheck()
: isObject_(false), isArray_(false), isBool_(false), isString_(false),
isNull_(false), isInt_(false), isInt64_(false), isUInt_(false), {}
isUInt64_(false), isIntegral_(false), isDouble_(false),
isNumeric_(false) {}
void ValueTest::checkIs(const Json::Value& value, const IsCheck& check) { void ValueTest::checkIs(const Json::Value& value, const IsCheck& check) {
JSONTEST_ASSERT_EQUAL(check.isObject_, value.isObject()); JSONTEST_ASSERT_EQUAL(check.isObject_, value.isObject());