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
diff --git a/include/json/features.h b/include/json/features.h
index 72eb6a8..ba25e8d 100644
--- a/include/json/features.h
+++ b/include/json/features.h
@@ -41,17 +41,17 @@
Features();
/// \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
/// false.
- bool strictRoot_;
+ bool strictRoot_{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.
- bool allowNumericKeys_;
+ bool allowNumericKeys_{false};
};
} // namespace Json
diff --git a/include/json/reader.h b/include/json/reader.h
index 58cb58b..1af5cb0 100644
--- a/include/json/reader.h
+++ b/include/json/reader.h
@@ -242,14 +242,14 @@
Nodes nodes_;
Errors errors_;
JSONCPP_STRING document_;
- Location begin_;
- Location end_;
- Location current_;
- Location lastValueEnd_;
- Value* lastValue_;
+ Location begin_{};
+ Location end_{};
+ Location current_{};
+ Location lastValueEnd_{};
+ Value* lastValue_{};
JSONCPP_STRING commentsBefore_;
Features features_;
- bool collectComments_;
+ bool collectComments_{};
}; // Reader
/** Interface for reading JSON from a char array.
diff --git a/include/json/value.h b/include/json/value.h
index 71bc65c..8321de7 100644
--- a/include/json/value.h
+++ b/include/json/value.h
@@ -630,7 +630,7 @@
void setComment(const char* text, size_t len);
- char* comment_;
+ char* comment_{nullptr};
};
// struct MemberNamesTransform
@@ -678,8 +678,8 @@
private:
enum Kind { kindNone = 0, kindIndex, kindKey };
JSONCPP_STRING key_;
- ArrayIndex index_;
- Kind kind_;
+ ArrayIndex index_{};
+ Kind kind_{kindNone};
};
/** \brief Experimental and untested: represents a "path" to access a node.
@@ -780,7 +780,7 @@
private:
Value::ObjectValues::iterator current_;
// Indicates that iterator is for a null value.
- bool isNull_;
+ bool isNull_{true};
public:
// For some reason, BORLAND needs these at the end, rather
diff --git a/include/json/writer.h b/include/json/writer.h
index 34e71ed..1653260 100644
--- a/include/json/writer.h
+++ b/include/json/writer.h
@@ -189,9 +189,9 @@
void writeValue(const Value& value);
JSONCPP_STRING document_;
- bool yamlCompatibilityEnabled_;
- bool dropNullPlaceholders_;
- bool omitEndingLineFeed_;
+ bool yamlCompatibilityEnabled_{false};
+ bool dropNullPlaceholders_{false};
+ bool omitEndingLineFeed_{false};
};
#if defined(_MSC_VER)
#pragma warning(pop)
@@ -257,9 +257,9 @@
ChildValues childValues_;
JSONCPP_STRING document_;
JSONCPP_STRING indentString_;
- unsigned int rightMargin_;
- unsigned int indentSize_;
- bool addChildValues_;
+ unsigned int rightMargin_{74};
+ unsigned int indentSize_{3};
+ bool addChildValues_{false};
};
#if defined(_MSC_VER)
#pragma warning(pop)
@@ -331,7 +331,7 @@
ChildValues childValues_;
JSONCPP_OSTREAM* document_;
JSONCPP_STRING indentString_;
- unsigned int rightMargin_;
+ unsigned int rightMargin_{74};
JSONCPP_STRING indentation_;
bool addChildValues_ : 1;
bool indented_ : 1;