diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index 54e2936..057b37a 100644 --- a/include/rapidjson/document.h +++ b/include/rapidjson/document.h @@ -42,6 +42,15 @@ RAPIDJSON_DIAG_OFF(4244) // conversion from kXxxFlags to 'uint16_t', possible lo RAPIDJSON_DIAG_OFF(effc++) #endif // __GNUC__ +#ifdef GetObject +// see https://github.com/Tencent/rapidjson/issues/1448 +// a former included windows.h might have defined a macro called GetObject, which affects +// GetObject defined here. This ensures the macro does not get applied +#pragma push_macro("GetObject") +#define RAPIDJSON_WINDOWS_GETOBJECT_WORKAROUND_APPLIED +#undef GetObject +#endif + #ifndef RAPIDJSON_NOMEMBERITERATORCLASS #include // std::random_access_iterator_tag #endif @@ -1602,7 +1611,9 @@ public: } Object GetObject() { RAPIDJSON_ASSERT(IsObject()); return Object(*this); } + Object GetObj() { RAPIDJSON_ASSERT(IsObject()); return Object(*this); } ConstObject GetObject() const { RAPIDJSON_ASSERT(IsObject()); return ConstObject(*this); } + ConstObject GetObj() const { RAPIDJSON_ASSERT(IsObject()); return ConstObject(*this); } //@} @@ -3008,4 +3019,9 @@ private: RAPIDJSON_NAMESPACE_END RAPIDJSON_DIAG_POP +#ifdef RAPIDJSON_WINDOWS_GETOBJECT_WORKAROUND_APPLIED +#pragma pop_macro("GetObject") +#undef RAPIDJSON_WINDOWS_GETOBJECT_WORKAROUND_APPLIED +#endif + #endif // RAPIDJSON_DOCUMENT_H_ diff --git a/test/unittest/platformtest.cpp b/test/unittest/platformtest.cpp index 5f9f539..ec7abc3 100644 --- a/test/unittest/platformtest.cpp +++ b/test/unittest/platformtest.cpp @@ -22,6 +22,7 @@ #endif #include "rapidjson/document.h" +#undef GetObject using namespace rapidjson; @@ -34,4 +35,6 @@ TEST(Platform, GetObject) { EXPECT_TRUE(o.IsObject()); auto sub = o.GetObject(); EXPECT_TRUE(sub.HasMember("pi")); + auto sub2 = o.GetObj(); + EXPECT_TRUE(sub2.HasMember("pi")); }