From 5de3b2187d18348712b54f9c723acfdc7ae751ec Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Fri, 11 Oct 2019 13:55:44 -0700 Subject: [PATCH 1/7] [clang-tidy] Add explicit to single argument constructor Found with hicpp-explicit-conversions Signed-off-by: Rosen Penev --- src/lib_json/json_reader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib_json/json_reader.cpp b/src/lib_json/json_reader.cpp index ac673ffce..958a39869 100644 --- a/src/lib_json/json_reader.cpp +++ b/src/lib_json/json_reader.cpp @@ -889,7 +889,7 @@ class OurReader { String message; }; - OurReader(OurFeatures const& features); + explicit OurReader(OurFeatures const& features); bool parse(const char* beginDoc, const char* endDoc, Value& root, bool collectComments = true); String getFormattedErrorMessages() const; From 0247ba356aba2cc5377f1c3b3abc090f1ca008b9 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Fri, 11 Oct 2019 13:57:19 -0700 Subject: [PATCH 2/7] [clang-tidy] Fix mismatching declaration Found with readability-inconsistent-declaration-parameter-name Signed-off-by: Rosen Penev --- include/json/value.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/json/value.h b/include/json/value.h index 7efc7c5e0..ac7df7f1f 100644 --- a/include/json/value.h +++ b/include/json/value.h @@ -657,7 +657,7 @@ class JSON_API Value { Comments& operator=(Comments&& that); bool has(CommentPlacement slot) const; String get(CommentPlacement slot) const; - void set(CommentPlacement slot, String s); + void set(CommentPlacement slot, String comment); private: using Array = std::array; From f808c0a0ae4d7a765b26f1232f4fc08f38bf0256 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Fri, 11 Oct 2019 14:03:17 -0700 Subject: [PATCH 3/7] [clang-tidy] Replace {} with = default Found with modernize-use-equals-default Signed-off-by: Rosen Penev --- src/lib_json/json_value.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index 30d9ad8ab..e3b464efe 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -203,7 +203,7 @@ namespace Json { #if JSON_USE_EXCEPTION Exception::Exception(String msg) : msg_(std::move(msg)) {} -Exception::~Exception() JSONCPP_NOEXCEPT {} +Exception::~Exception() JSONCPP_NOEXCEPT = default; char const* Exception::what() const JSONCPP_NOEXCEPT { return msg_.c_str(); } RuntimeError::RuntimeError(String const& msg) : Exception(msg) {} LogicError::LogicError(String const& msg) : Exception(msg) {} @@ -1543,7 +1543,7 @@ Value::iterator Value::end() { // class PathArgument // ////////////////////////////////////////////////////////////////// -PathArgument::PathArgument() {} +PathArgument::PathArgument() = default; PathArgument::PathArgument(ArrayIndex index) : index_(index), kind_(kindIndex) {} From 20719432ca3bba8ec412f91e8c962c02e7a1b18e Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Fri, 11 Oct 2019 14:05:21 -0700 Subject: [PATCH 4/7] [clang-tidy] Remove redundant .c_Str Found with readability-redundant-string-cstr Signed-off-by: Rosen Penev --- src/lib_json/json_value.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index e3b464efe..a3424717c 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -1551,7 +1551,7 @@ PathArgument::PathArgument(ArrayIndex index) PathArgument::PathArgument(const char* key) : key_(key), kind_(kindKey) {} PathArgument::PathArgument(const String& key) - : key_(key.c_str()), kind_(kindKey) {} + : key_(key), kind_(kindKey) {} // class Path // ////////////////////////////////////////////////////////////////// From b8e04b48fb263d391162ae6270286e1fe0f7bc6f Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Fri, 11 Oct 2019 14:09:28 -0700 Subject: [PATCH 5/7] [clang-tidy] Simplify boolean expressions Found with readability-simplify-boolean-expr Signed-off-by: Rosen Penev --- src/lib_json/json_value.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index a3424717c..8a7c49f91 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -492,7 +492,7 @@ int Value::compare(const Value& other) const { bool Value::operator<(const Value& other) const { int typeDelta = type() - other.type(); if (typeDelta) - return typeDelta < 0 ? true : false; + return typeDelta < 0; switch (type()) { case nullValue: return false; @@ -506,10 +506,7 @@ bool Value::operator<(const Value& other) const { return value_.bool_ < other.value_.bool_; case stringValue: { if ((value_.string_ == nullptr) || (other.value_.string_ == nullptr)) { - if (other.value_.string_) - return true; - else - return false; + return other.value_.string_ != nullptr; } unsigned this_len; unsigned other_len; @@ -821,9 +818,9 @@ bool Value::asBool() const { case nullValue: return false; case intValue: - return value_.int_ ? true : false; + return value_.int_ != 0; case uintValue: - return value_.uint_ ? true : false; + return value_.uint_ != 0; case realValue: { // According to JavaScript language zero or NaN is regarded as false const auto value_classification = std::fpclassify(value_.real_); @@ -839,7 +836,7 @@ bool Value::isConvertibleTo(ValueType other) const { switch (other) { case nullValue: return (isNumeric() && asDouble() == 0.0) || - (type() == booleanValue && value_.bool_ == false) || + (type() == booleanValue && !value_.bool_) || (type() == stringValue && asString().empty()) || (type() == arrayValue && value_.map_->empty()) || (type() == objectValue && value_.map_->empty()) || From 88551b8ed69d6cb8e1cb208a9c122be6fadc2d44 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Fri, 11 Oct 2019 14:12:44 -0700 Subject: [PATCH 6/7] [clang-tidy] Use std::move Found with modernize-pass-by-value Signed-off-by: Rosen Penev --- include/json/value.h | 2 +- src/lib_json/json_value.cpp | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/include/json/value.h b/include/json/value.h index ac7df7f1f..e3c3d2b7e 100644 --- a/include/json/value.h +++ b/include/json/value.h @@ -681,7 +681,7 @@ class JSON_API PathArgument { PathArgument(); PathArgument(ArrayIndex index); PathArgument(const char* key); - PathArgument(const String& key); + PathArgument(String key); private: enum Kind { kindNone = 0, kindIndex, kindKey }; diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index 8a7c49f91..2f30d422d 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -1547,8 +1547,7 @@ PathArgument::PathArgument(ArrayIndex index) PathArgument::PathArgument(const char* key) : key_(key), kind_(kindKey) {} -PathArgument::PathArgument(const String& key) - : key_(key), kind_(kindKey) {} +PathArgument::PathArgument(String key) : key_(std::move(key)), kind_(kindKey) {} // class Path // ////////////////////////////////////////////////////////////////// From f7f1f2a6c093ba65f93c1278d4fb7cd2634a194d Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Fri, 11 Oct 2019 14:15:46 -0700 Subject: [PATCH 7/7] [clang-tidy] Uppercase literal suffixes Found with hicpp-uppercase-literal-suffix Signed-off-by: Rosen Penev --- src/lib_json/json_value.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index 2f30d422d..1130cce10 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -261,7 +261,7 @@ Value::CZString::CZString(CZString&& other) Value::CZString::~CZString() { if (cstr_ && storage_.policy_ == duplicate) { releaseStringValue(const_cast(cstr_), - storage_.length_ + 1u); // +1 for null terminating + storage_.length_ + 1U); // +1 for null terminating // character for sake of // completeness but not actually // necessary @@ -804,7 +804,7 @@ float Value::asFloat() const { case nullValue: return 0.0; case booleanValue: - return value_.bool_ ? 1.0f : 0.0f; + return value_.bool_ ? 1.0F : 0.0F; default: break; } @@ -891,7 +891,7 @@ ArrayIndex Value::size() const { bool Value::empty() const { if (isNull() || isArray() || isObject()) - return size() == 0u; + return size() == 0U; else return false; }