Skip to content

Commit 052c122

Browse files
committed
STYLE: Pefer = default to explicitly trivial implementations
This check replaces default bodies of special member functions with = default;. The explicitly defaulted function declarations enable more opportunities in optimization, because the compiler might treat explicitly defaulted functions as trivial. Additionally, the C++11 use of = default more clearly expreses the intent for the special member functions. 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-equals-default -header-filter=.* -fix
1 parent 0e82247 commit 052c122

File tree

8 files changed

+22
-22
lines changed

8 files changed

+22
-22
lines changed

Diff for: include/json/reader.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ class JSON_API Reader {
256256
*/
257257
class JSON_API CharReader {
258258
public:
259-
virtual ~CharReader() {}
259+
virtual ~CharReader() = default;
260260
/** \brief Read a Value from a <a HREF="http://www.json.org">JSON</a>
261261
document.
262262
* The document must be a UTF-8 encoded string containing the document to
@@ -282,7 +282,7 @@ class JSON_API CharReader {
282282

283283
class JSON_API Factory {
284284
public:
285-
virtual ~Factory() {}
285+
virtual ~Factory() = default;
286286
/** \brief Allocate a CharReader via operator new().
287287
* \throw std::exception if something goes wrong (e.g. invalid settings)
288288
*/

Diff for: include/json/writer.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API FastWriter
169169
: public Writer {
170170
public:
171171
FastWriter();
172-
~FastWriter() override {}
172+
~FastWriter() override = default;
173173

174174
void enableYAMLCompatibility();
175175

@@ -229,7 +229,7 @@ class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API
229229
StyledWriter : public Writer {
230230
public:
231231
StyledWriter();
232-
~StyledWriter() override {}
232+
~StyledWriter() override = default;
233233

234234
public: // overridden from Writer
235235
/** \brief Serialize a Value in <a HREF="http://www.json.org">JSON</a> format.
@@ -301,7 +301,7 @@ class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API
301301
* \param indentation Each level will be indented by this amount extra.
302302
*/
303303
StyledStreamWriter(JSONCPP_STRING indentation = "\t");
304-
~StyledStreamWriter() {}
304+
~StyledStreamWriter() = default;
305305

306306
public:
307307
/** \brief Serialize a Value in <a HREF="http://www.json.org">JSON</a> format.

Diff for: src/lib_json/json_reader.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ typedef std::auto_ptr<CharReader> CharReaderPtr;
6060
// ////////////////////////////////
6161

6262
Features::Features()
63-
{}
63+
= default;
6464

6565
Features Features::all() { return {}; }
6666

@@ -1907,7 +1907,7 @@ class OurCharReader : public CharReader {
19071907
};
19081908

19091909
CharReaderBuilder::CharReaderBuilder() { setDefaults(&settings_); }
1910-
CharReaderBuilder::~CharReaderBuilder() {}
1910+
CharReaderBuilder::~CharReaderBuilder() = default;
19111911
CharReader* CharReaderBuilder::newCharReader() const {
19121912
bool collectComments = settings_["collectComments"].asBool();
19131913
OurFeatures features = OurFeatures::all();

Diff for: src/lib_json/json_value.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ static inline void releaseStringValue(char* value, unsigned) { free(value); }
214214
namespace Json {
215215

216216
Exception::Exception(JSONCPP_STRING msg) : msg_(std::move(msg)) {}
217-
Exception::~Exception() JSONCPP_NOEXCEPT {}
217+
Exception::~Exception() JSONCPP_NOEXCEPT = default;
218218
char const* Exception::what() const JSONCPP_NOEXCEPT { return msg_.c_str(); }
219219
RuntimeError::RuntimeError(JSONCPP_STRING const& msg) : Exception(msg) {}
220220
LogicError::LogicError(JSONCPP_STRING const& msg) : Exception(msg) {}
@@ -233,7 +233,7 @@ JSONCPP_NORETURN void throwLogicError(JSONCPP_STRING const& msg) {
233233
// //////////////////////////////////////////////////////////////////
234234
// //////////////////////////////////////////////////////////////////
235235

236-
Value::CommentInfo::CommentInfo() {}
236+
Value::CommentInfo::CommentInfo() = default;
237237

238238
Value::CommentInfo::~CommentInfo() {
239239
if (comment_)

Diff for: src/lib_json/json_valueiterator.inl

+3-3
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ char const* ValueIteratorBase::memberName(char const** end) const {
123123
// //////////////////////////////////////////////////////////////////
124124
// //////////////////////////////////////////////////////////////////
125125

126-
ValueConstIterator::ValueConstIterator() {}
126+
ValueConstIterator::ValueConstIterator() = default;
127127

128128
ValueConstIterator::ValueConstIterator(
129129
const Value::ObjectValues::iterator& current)
@@ -146,7 +146,7 @@ operator=(const ValueIteratorBase& other) {
146146
// //////////////////////////////////////////////////////////////////
147147
// //////////////////////////////////////////////////////////////////
148148

149-
ValueIterator::ValueIterator() {}
149+
ValueIterator::ValueIterator() = default;
150150

151151
ValueIterator::ValueIterator(const Value::ObjectValues::iterator& current)
152152
: ValueIteratorBase(current) {}
@@ -157,7 +157,7 @@ ValueIterator::ValueIterator(const ValueConstIterator& other)
157157
}
158158

159159
ValueIterator::ValueIterator(const ValueIterator& other)
160-
: ValueIteratorBase(other) {}
160+
= default;
161161

162162
ValueIterator& ValueIterator::operator=(const SelfType& other) {
163163
copy(other);

Diff for: src/lib_json/json_writer.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -346,14 +346,14 @@ JSONCPP_STRING valueToQuotedString(const char* value) {
346346

347347
// Class Writer
348348
// //////////////////////////////////////////////////////////////////
349-
Writer::~Writer() {}
349+
Writer::~Writer() = default;
350350

351351
// Class FastWriter
352352
// //////////////////////////////////////////////////////////////////
353353

354354
FastWriter::FastWriter()
355355

356-
{}
356+
= default;
357357

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

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

430430
StyledWriter::StyledWriter()
431-
{}
431+
= default;
432432

433433
JSONCPP_STRING StyledWriter::write(const Value& root) {
434434
document_.clear();
@@ -1156,10 +1156,10 @@ bool BuiltStyledStreamWriter::hasCommentForValue(const Value& value) {
11561156
// StreamWriter
11571157

11581158
StreamWriter::StreamWriter() : sout_(nullptr) {}
1159-
StreamWriter::~StreamWriter() {}
1160-
StreamWriter::Factory::~Factory() {}
1159+
StreamWriter::~StreamWriter() = default;
1160+
StreamWriter::Factory::~Factory() = default;
11611161
StreamWriterBuilder::StreamWriterBuilder() { setDefaults(&settings_); }
1162-
StreamWriterBuilder::~StreamWriterBuilder() {}
1162+
StreamWriterBuilder::~StreamWriterBuilder() = default;
11631163
StreamWriter* StreamWriterBuilder::newStreamWriter() const {
11641164
JSONCPP_STRING indentation = settings_["indentation"].asString();
11651165
JSONCPP_STRING cs_str = settings_["commentStyle"].asString();

Diff for: src/test_lib_json/jsontest.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,9 @@ TestResult& TestResult::operator<<(bool value) {
207207
// class TestCase
208208
// //////////////////////////////////////////////////////////////////
209209

210-
TestCase::TestCase() {}
210+
TestCase::TestCase() = default;
211211

212-
TestCase::~TestCase() {}
212+
TestCase::~TestCase() = default;
213213

214214
void TestCase::run(TestResult& result) {
215215
result_ = &result;
@@ -219,7 +219,7 @@ void TestCase::run(TestResult& result) {
219219
// class Runner
220220
// //////////////////////////////////////////////////////////////////
221221

222-
Runner::Runner() {}
222+
Runner::Runner() = default;
223223

224224
Runner& Runner::add(TestCaseFactory factory) {
225225
tests_.push_back(factory);

Diff for: src/test_lib_json/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1332,7 +1332,7 @@ void ValueTest::checkMemberCount(Json::Value& value,
13321332

13331333
ValueTest::IsCheck::IsCheck()
13341334

1335-
{}
1335+
= default;
13361336

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

0 commit comments

Comments
 (0)