Issue #958: Travis CI should enforce clang-format standards (#1026)
* Issue #958: Travis CI should enfore clang-format standards
This patch adds clang format support to the travis bots.
* Update path
* Roll back to version 8 since 9 is in test
* Cleanup clang
* Revert "Delete JSONCPP_DEPRECATED, use [[deprecated]] instead. (#978)" (#1029)
This reverts commit b27c83f691a03f521a1b3b99eefa2973f8e2bfcd.
diff --git a/include/json/config.h b/include/json/config.h
index 0ff5968..cbb5950 100644
--- a/include/json/config.h
+++ b/include/json/config.h
@@ -74,8 +74,8 @@
#if defined(_MSC_VER) && _MSC_VER < 1900
// As recommended at
// https://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010
-extern JSON_API int
-msvc_pre1900_c99_snprintf(char* outBuf, size_t size, const char* format, ...);
+extern JSON_API int msvc_pre1900_c99_snprintf(char* outBuf, size_t size,
+ const char* format, ...);
#define jsoncpp_snprintf msvc_pre1900_c99_snprintf
#else
#define jsoncpp_snprintf std::snprintf
@@ -104,9 +104,26 @@
#define JSONCPP_OP_EXPLICIT
#endif
-#if defined(__clang__)
-#define JSON_USE_INT64_DOUBLE_CONVERSION 1
-#elif defined(__GNUC__) && (__GNUC__ >= 6)
+#ifdef __clang__
+#if __has_extension(attribute_deprecated_with_message)
+#define JSONCPP_DEPRECATED(message) __attribute__((deprecated(message)))
+#endif
+#elif defined(__GNUC__) // not clang (gcc comes later since clang emulates gcc)
+#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))
+#define JSONCPP_DEPRECATED(message) __attribute__((deprecated(message)))
+#elif (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
+#define JSONCPP_DEPRECATED(message) __attribute__((__deprecated__))
+#endif // GNUC version
+#elif defined(_MSC_VER) // MSVC (after clang because clang on Windows emulates
+ // MSVC)
+#define JSONCPP_DEPRECATED(message) __declspec(deprecated(message))
+#endif // __clang__ || __GNUC__ || _MSC_VER
+
+#if !defined(JSONCPP_DEPRECATED)
+#define JSONCPP_DEPRECATED(message)
+#endif // if !defined(JSONCPP_DEPRECATED)
+
+#if defined(__clang__) || (defined(__GNUC__) && (__GNUC__ >= 6))
#define JSON_USE_INT64_DOUBLE_CONVERSION 1
#endif
@@ -139,16 +156,16 @@
#endif // if defined(JSON_NO_INT64)
template <typename T>
-using Allocator = typename std::conditional<JSONCPP_USING_SECURE_MEMORY,
- SecureAllocator<T>,
- std::allocator<T>>::type;
+using Allocator =
+ typename std::conditional<JSONCPP_USING_SECURE_MEMORY, SecureAllocator<T>,
+ std::allocator<T>>::type;
using String = std::basic_string<char, std::char_traits<char>, Allocator<char>>;
-using IStringStream = std::basic_istringstream<String::value_type,
- String::traits_type,
- String::allocator_type>;
-using OStringStream = std::basic_ostringstream<String::value_type,
- String::traits_type,
- String::allocator_type>;
+using IStringStream =
+ std::basic_istringstream<String::value_type, String::traits_type,
+ String::allocator_type>;
+using OStringStream =
+ std::basic_ostringstream<String::value_type, String::traits_type,
+ String::allocator_type>;
using IStream = std::istream;
using OStream = std::ostream;
} // namespace Json
diff --git a/include/json/reader.h b/include/json/reader.h
index fb2365a..359c1eb 100644
--- a/include/json/reader.h
+++ b/include/json/reader.h
@@ -25,10 +25,6 @@
#pragma pack(push, 8)
-#if defined(_MSC_VER)
-#pragma warning(disable : 4996)
-#endif
-
namespace Json {
/** \brief Unserialize a <a HREF="http://www.json.org">JSON</a> document into a
@@ -36,8 +32,9 @@
*
* \deprecated Use CharReader and CharReaderBuilder.
*/
-class [[deprecated(
- "deprecated Use CharReader and CharReaderBuilder.")]] JSON_API Reader {
+
+class JSONCPP_DEPRECATED(
+ "Use CharReader and CharReaderBuilder instead.") JSON_API Reader {
public:
typedef char Char;
typedef const Char* Location;
@@ -55,10 +52,12 @@
/** \brief Constructs a Reader allowing all features for parsing.
*/
+ JSONCPP_DEPRECATED("Use CharReader and CharReaderBuilder instead")
Reader();
/** \brief Constructs a Reader allowing the specified feature set for parsing.
*/
+ JSONCPP_DEPRECATED("Use CharReader and CharReaderBuilder instead")
Reader(const Features& features);
/** \brief Read a Value from a <a HREF="http://www.json.org">JSON</a>
@@ -99,7 +98,7 @@
/// \brief Parse from input stream.
/// \see Json::operator>>(std::istream&, Json::Value&).
- bool parse(IStream & is, Value & root, bool collectComments = true);
+ bool parse(IStream& is, Value& root, bool collectComments = true);
/** \brief Returns a user friendly string that list errors in the parsed
* document.
@@ -109,8 +108,8 @@
* occurred during parsing.
* \deprecated Use getFormattedErrorMessages() instead (typo fix).
*/
- [[deprecated("Use getFormattedErrorMessages() instead.")]] String
- getFormatedErrorMessages() const;
+ JSONCPP_DEPRECATED("Use getFormattedErrorMessages() instead.")
+ String getFormatedErrorMessages() const;
/** \brief Returns a user friendly string that list errors in the parsed
* document.
@@ -190,7 +189,7 @@
typedef std::deque<ErrorInfo> Errors;
- bool readToken(Token & token);
+ bool readToken(Token& token);
void skipSpaces();
bool match(const Char* pattern, int patternLength);
bool readComment();
@@ -199,17 +198,17 @@
bool readString();
void readNumber();
bool readValue();
- bool readObject(Token & token);
- bool readArray(Token & token);
- bool decodeNumber(Token & token);
- bool decodeNumber(Token & token, Value & decoded);
- bool decodeString(Token & token);
- bool decodeString(Token & token, String & decoded);
- bool decodeDouble(Token & token);
- bool decodeDouble(Token & token, Value & decoded);
- bool decodeUnicodeCodePoint(Token & token, Location & current, Location end,
+ bool readObject(Token& token);
+ bool readArray(Token& token);
+ bool decodeNumber(Token& token);
+ bool decodeNumber(Token& token, Value& decoded);
+ bool decodeString(Token& token);
+ bool decodeString(Token& token, String& decoded);
+ bool decodeDouble(Token& token);
+ bool decodeDouble(Token& token, Value& decoded);
+ bool decodeUnicodeCodePoint(Token& token, Location& current, Location end,
unsigned int& unicode);
- bool decodeUnicodeEscapeSequence(Token & token, Location & current,
+ bool decodeUnicodeEscapeSequence(Token& token, Location& current,
Location end, unsigned int& unicode);
bool addError(const String& message, Token& token, Location extra = nullptr);
bool recoverFromError(TokenType skipUntilToken);
@@ -218,11 +217,11 @@
void skipUntilSpace();
Value& currentValue();
Char getNextChar();
- void getLocationLineAndColumn(Location location, int& line, int& column)
- const;
+ void getLocationLineAndColumn(Location location, int& line,
+ int& column) const;
String getLocationLineAndColumn(Location location) const;
void addComment(Location begin, Location end, CommentPlacement placement);
- void skipCommentTokens(Token & token);
+ void skipCommentTokens(Token& token);
static bool containsNewLine(Location begin, Location end);
static String normalizeEOL(Location begin, Location end);
@@ -262,9 +261,7 @@
* \return \c true if the document was successfully parsed, \c false if an
* error occurred.
*/
- virtual bool parse(char const* beginDoc,
- char const* endDoc,
- Value* root,
+ virtual bool parse(char const* beginDoc, char const* endDoc, Value* root,
String* errs) = 0;
class JSON_API Factory {
@@ -364,9 +361,7 @@
* Someday we might have a real StreamReader, but for now this
* is convenient.
*/
-bool JSON_API parseFromStream(CharReader::Factory const&,
- IStream&,
- Value* root,
+bool JSON_API parseFromStream(CharReader::Factory const&, IStream&, Value* root,
String* errs);
/** \brief Read from 'sin' into 'root'.
diff --git a/include/json/value.h b/include/json/value.h
index aa7bc54..a0a5a11 100644
--- a/include/json/value.h
+++ b/include/json/value.h
@@ -493,8 +493,8 @@
/// Return the member named key if it exist, defaultValue otherwise.
/// \note deep copy
/// \note key may contain embedded nulls.
- Value
- get(const char* begin, const char* end, const Value& defaultValue) const;
+ Value get(const char* begin, const char* end,
+ const Value& defaultValue) const;
/// Return the member named key if it exist, defaultValue otherwise.
/// \note deep copy
/// \param key may contain embedded nulls.
@@ -567,8 +567,8 @@
//# endif
/// \deprecated Always pass len.
- [[deprecated("Use setComment(String const&) instead.")]] void
- setComment(const char* comment, CommentPlacement placement) {
+ JSONCPP_DEPRECATED("Use setComment(String const&) instead.")
+ void setComment(const char* comment, CommentPlacement placement) {
setComment(String(comment, strlen(comment)), placement);
}
/// Comments must be //... or /* ... */
@@ -691,8 +691,7 @@
*/
class JSON_API Path {
public:
- Path(const String& path,
- const PathArgument& a1 = PathArgument(),
+ Path(const String& path, const PathArgument& a1 = PathArgument(),
const PathArgument& a2 = PathArgument(),
const PathArgument& a3 = PathArgument(),
const PathArgument& a4 = PathArgument(),
@@ -709,10 +708,8 @@
typedef std::vector<PathArgument> Args;
void makePath(const String& path, const InArgs& in);
- void addPathInArg(const String& path,
- const InArgs& in,
- InArgs::const_iterator& itInArg,
- PathArgument::Kind kind);
+ void addPathInArg(const String& path, const InArgs& in,
+ InArgs::const_iterator& itInArg, PathArgument::Kind kind);
static void invalidPath(const String& path, int location);
Args args_;
@@ -753,7 +750,8 @@
/// objectValue.
/// \deprecated This cannot be used for UTF-8 strings, since there can be
/// embedded nulls.
- [[deprecated("Use `key = name();` instead.")]] char const* memberName() const;
+ JSONCPP_DEPRECATED("Use `key = name();` instead.")
+ char const* memberName() const;
/// Return the member name of the referenced Value, or NULL if it is not an
/// objectValue.
/// \note Better version than memberName(). Allows embedded nulls.
diff --git a/include/json/writer.h b/include/json/writer.h
index 9799a3b..a72c06a 100644
--- a/include/json/writer.h
+++ b/include/json/writer.h
@@ -145,7 +145,7 @@
/** \brief Abstract class for writers.
* \deprecated Use StreamWriter. (And really, this is an implementation detail.)
*/
-class [[deprecated("Use StreamWriter instead")]] JSON_API Writer {
+class JSONCPP_DEPRECATED("Use StreamWriter instead") JSON_API Writer {
public:
virtual ~Writer();
@@ -165,7 +165,7 @@
#pragma warning(push)
#pragma warning(disable : 4996) // Deriving from deprecated class
#endif
-class [[deprecated("Use StreamWriterBuilder instead")]] JSON_API FastWriter
+class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API FastWriter
: public Writer {
public:
FastWriter();
@@ -225,8 +225,8 @@
#pragma warning(push)
#pragma warning(disable : 4996) // Deriving from deprecated class
#endif
-class [[deprecated("Use StreamWriterBuilder instead")]] JSON_API StyledWriter
- : public Writer {
+class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API
+ StyledWriter : public Writer {
public:
StyledWriter();
~StyledWriter() override = default;
@@ -294,8 +294,8 @@
#pragma warning(push)
#pragma warning(disable : 4996) // Deriving from deprecated class
#endif
-class [[deprecated(
- "Use StreamWriterBuilder instead")]] JSON_API StyledStreamWriter {
+class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API
+ StyledStreamWriter {
public:
/**
* \param indentation Each level will be indented by this amount extra.
@@ -310,7 +310,7 @@
* \note There is no point in deriving from Writer, since write() should not
* return a value.
*/
- void write(OStream & out, const Value& root);
+ void write(OStream& out, const Value& root);
private:
void writeValue(const Value& value);
@@ -346,10 +346,9 @@
#endif // if defined(JSON_HAS_INT64)
String JSON_API valueToString(LargestInt value);
String JSON_API valueToString(LargestUInt value);
-String JSON_API
-valueToString(double value,
- unsigned int precision = Value::defaultRealPrecision,
- PrecisionType precisionType = PrecisionType::significantDigits);
+String JSON_API valueToString(
+ double value, unsigned int precision = Value::defaultRealPrecision,
+ PrecisionType precisionType = PrecisionType::significantDigits);
String JSON_API valueToString(bool value);
String JSON_API valueToQuotedString(const char* value);