clang-tidy fixes (#1033)

* [clang-tidy] Replace C typedef with C++ using

Found with modernize-use-using

Added to .clang-tidy file.

Signed-off-by: Rosen Penev <rosenp@gmail.com>

* [clang-tidy] Remove redundant member init

Found with readability-redundant-member-init

Added to .clang-tidy

* [clang-tidy] Replace C casts with C++ ones

Found with google-readability-casting

Signed-off-by: Rosen Penev <rosenp@gmail.com>

* [clang-tidy] Use default member init

Found with modernize-use-default-member-init

Signed-off-by: Rosen Penev <rosenp@gmail.com>
This commit is contained in:
Rosen Penev 2019-09-25 14:03:30 -07:00 committed by Jordan Bayles
parent e9ccbe0145
commit ae4dc9aa62
4 changed files with 27 additions and 17 deletions

11
.clang-tidy Normal file
View File

@ -0,0 +1,11 @@
---
Checks: 'google-readability-casting,modernize-use-default-member-init,modernize-use-using,readability-redundant-member-init'
WarningsAsErrors: ''
HeaderFilterRegex: ''
AnalyzeTemporaryDtors: false
FormatStyle: none
CheckOptions:
- key: modernize-use-using.IgnoreMacros
value: '0'
...

View File

@ -51,7 +51,7 @@ static size_t const stackLimit_g =
namespace Json { namespace Json {
#if __cplusplus >= 201103L || (defined(_CPPLIB_VER) && _CPPLIB_VER >= 520) #if __cplusplus >= 201103L || (defined(_CPPLIB_VER) && _CPPLIB_VER >= 520)
typedef std::unique_ptr<CharReader> CharReaderPtr; using CharReaderPtr = std::unique_ptr<CharReader>;
#else #else
typedef std::auto_ptr<CharReader> CharReaderPtr; typedef std::auto_ptr<CharReader> CharReaderPtr;
#endif #endif
@ -86,11 +86,10 @@ bool Reader::containsNewLine(Reader::Location begin, Reader::Location end) {
// ////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////
Reader::Reader() Reader::Reader()
: errors_(), document_(), commentsBefore_(), features_(Features::all()) {} : features_(Features::all()) {}
Reader::Reader(const Features& features) Reader::Reader(const Features& features)
: errors_(), document_(), begin_(), end_(), current_(), lastValueEnd_(), : features_(features) {
lastValue_(), commentsBefore_(), features_(features), collectComments_() {
} }
bool Reader::parse(const std::string& document, bool Reader::parse(const std::string& document,
@ -111,7 +110,7 @@ bool Reader::parse(std::istream& is, Value& root, bool collectComments) {
// Since String is reference-counted, this at least does not // Since String is reference-counted, this at least does not
// create an extra copy. // create an extra copy.
String doc; String doc;
std::getline(is, doc, (char)EOF); std::getline(is, doc, static_cast<char>EOF);
return parse(doc.data(), doc.data() + doc.size(), root, collectComments); return parse(doc.data(), doc.data() + doc.size(), root, collectComments);
} }
@ -895,8 +894,8 @@ OurFeatures OurFeatures::all() { return {}; }
// for implementing JSON reading. // for implementing JSON reading.
class OurReader { class OurReader {
public: public:
typedef char Char; using Char = char;
typedef const Char* Location; using Location = const Char *;
struct StructuredError { struct StructuredError {
ptrdiff_t offset_start; ptrdiff_t offset_start;
ptrdiff_t offset_limit; ptrdiff_t offset_limit;
@ -952,7 +951,7 @@ private:
Location extra_; Location extra_;
}; };
typedef std::deque<ErrorInfo> Errors; using Errors = std::deque<ErrorInfo>;
bool readToken(Token& token); bool readToken(Token& token);
void skipSpaces(); void skipSpaces();
@ -997,7 +996,7 @@ private:
static String normalizeEOL(Location begin, Location end); static String normalizeEOL(Location begin, Location end);
static bool containsNewLine(Location begin, Location end); static bool containsNewLine(Location begin, Location end);
typedef std::stack<Value*> Nodes; using Nodes = std::stack<Value *>;
Nodes nodes_; Nodes nodes_;
Errors errors_; Errors errors_;
String document_; String document_;
@ -1023,8 +1022,8 @@ bool OurReader::containsNewLine(OurReader::Location begin,
} }
OurReader::OurReader(OurFeatures const& features) OurReader::OurReader(OurFeatures const& features)
: errors_(), document_(), begin_(), end_(), current_(), lastValueEnd_(), : begin_(), end_(), current_(), lastValueEnd_(),
lastValue_(), commentsBefore_(), features_(features), collectComments_() { lastValue_(), features_(features), collectComments_() {
} }
bool OurReader::parse(const char* beginDoc, bool OurReader::parse(const char* beginDoc,

View File

@ -1547,16 +1547,16 @@ Value::iterator Value::end() {
// class PathArgument // class PathArgument
// ////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////
PathArgument::PathArgument() : key_() {} PathArgument::PathArgument() {}
PathArgument::PathArgument(ArrayIndex index) PathArgument::PathArgument(ArrayIndex index)
: key_(), index_(index), kind_(kindIndex) {} : index_(index), kind_(kindIndex) {}
PathArgument::PathArgument(const char* key) PathArgument::PathArgument(const char* key)
: key_(key), index_(), kind_(kindKey) {} : key_(key), kind_(kindKey) {}
PathArgument::PathArgument(const String& key) PathArgument::PathArgument(const String& key)
: key_(key.c_str()), index_(), kind_(kindKey) {} : key_(key.c_str()), kind_(kindKey) {}
// class Path // class Path
// ////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////

View File

@ -84,7 +84,7 @@
namespace Json { namespace Json {
#if __cplusplus >= 201103L || (defined(_CPPLIB_VER) && _CPPLIB_VER >= 520) #if __cplusplus >= 201103L || (defined(_CPPLIB_VER) && _CPPLIB_VER >= 520)
typedef std::unique_ptr<StreamWriter> StreamWriterPtr; using StreamWriterPtr = std::unique_ptr<StreamWriter>;
#else #else
typedef std::auto_ptr<StreamWriter> StreamWriterPtr; typedef std::auto_ptr<StreamWriter> StreamWriterPtr;
#endif #endif
@ -887,7 +887,7 @@ private:
void writeCommentAfterValueOnSameLine(Value const& root); void writeCommentAfterValueOnSameLine(Value const& root);
static bool hasCommentForValue(const Value& value); static bool hasCommentForValue(const Value& value);
typedef std::vector<String> ChildValues; using ChildValues = std::vector<String>;
ChildValues childValues_; ChildValues childValues_;
String indentString_; String indentString_;