diff --git a/include/rapidjson/prettywriter.h b/include/rapidjson/prettywriter.h index c6f0216e9..abd964f6f 100644 --- a/include/rapidjson/prettywriter.h +++ b/include/rapidjson/prettywriter.h @@ -22,6 +22,11 @@ RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_OFF(effc++) #endif +#if defined(__clang__) +RAPIDJSON_DIAG_PUSH +RAPIDJSON_DIAG_OFF(c++98-compat) +#endif + RAPIDJSON_NAMESPACE_BEGIN //! Combination of PrettyWriter format flags. @@ -57,6 +62,11 @@ class PrettyWriter : public Writer(rhs)), indentChar_(rhs.indentChar_), indentCharCount_(rhs.indentCharCount_), formatOptions_(rhs.formatOptions_) {} +#endif + //! Set custom indentation. /*! \param indentChar Character for indentation. Must be whitespace character (' ', '\\t', '\\n', '\\r'). \param indentCharCount Number of indent characters for each indentation level. @@ -254,6 +264,10 @@ class PrettyWriter : public Writer PrettyWriter { + PrettyWriter writer(target); + writer.StartObject(); + writer.Key("a"); + writer.Int(1); + return std::move(writer); + }; + + PrettyWriter writer(writerGen(buffer)); + writer.EndObject(); + EXPECT_TRUE(writer.IsComplete()); + EXPECT_STREQ( + "{\n" + " \"a\": 1\n" + "}", + buffer.GetString()); +} +#endif + +#ifdef __clang__ +RAPIDJSON_DIAG_POP +#endif diff --git a/test/unittest/writertest.cpp b/test/unittest/writertest.cpp index 29f762609..b3124bfeb 100644 --- a/test/unittest/writertest.cpp +++ b/test/unittest/writertest.cpp @@ -20,6 +20,11 @@ #include "rapidjson/stringbuffer.h" #include "rapidjson/memorybuffer.h" +#ifdef __clang__ +RAPIDJSON_DIAG_PUSH +RAPIDJSON_DIAG_OFF(c++98-compat) +#endif + using namespace rapidjson; TEST(Writer, Compact) { @@ -495,3 +500,25 @@ TEST(Writer, RawValue) { EXPECT_TRUE(writer.IsComplete()); EXPECT_STREQ("{\"a\":1,\"raw\":[\"Hello\\nWorld\", 123.456]}", buffer.GetString()); } + +#if RAPIDJSON_HAS_CXX11_RVALUE_REFS +TEST(Writer, MoveCtor) { + StringBuffer buffer; + auto writerGen=[](StringBuffer &target) -> Writer { + Writer writer(target); + writer.StartObject(); + writer.Key("a"); + writer.Int(1); + return std::move(writer); + }; + + Writer writer(writerGen(buffer)); + writer.EndObject(); + EXPECT_TRUE(writer.IsComplete()); + EXPECT_STREQ("{\"a\":1}", buffer.GetString()); +} +#endif + +#ifdef __clang__ +RAPIDJSON_DIAG_POP +#endif