From c8a8cfcd4b09ee762a129478f75d3f95f50265c9 Mon Sep 17 00:00:00 2001 From: ycqiu <429148848@qq.com> Date: Tue, 6 Oct 2015 16:46:19 +0800 Subject: [PATCH] fix In value.h, ValueConstIterator can convert to ValueIterator, I think that is a bug. the correct way is ValueIterator can convert to ValueConstIterator. --- include/json/value.h | 3 ++- src/lib_json/json_valueiterator.inl | 7 ++++++- src/test_lib_json/main.cpp | 5 +++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/include/json/value.h b/include/json/value.h index 237aa53..7f3ad9b 100644 --- a/include/json/value.h +++ b/include/json/value.h @@ -738,6 +738,7 @@ public: typedef ValueConstIterator SelfType; ValueConstIterator(); + ValueConstIterator(ValueIterator const& other); private: /*! \internal Use by Value to create an iterator. @@ -787,7 +788,7 @@ public: typedef ValueIterator SelfType; ValueIterator(); - ValueIterator(const ValueConstIterator& other); + explicit ValueIterator(const ValueConstIterator& other); ValueIterator(const ValueIterator& other); private: diff --git a/src/lib_json/json_valueiterator.inl b/src/lib_json/json_valueiterator.inl index b3bbc35..ec9c851 100644 --- a/src/lib_json/json_valueiterator.inl +++ b/src/lib_json/json_valueiterator.inl @@ -129,6 +129,9 @@ ValueConstIterator::ValueConstIterator( const Value::ObjectValues::iterator& current) : ValueIteratorBase(current) {} +ValueConstIterator::ValueConstIterator(ValueIterator const& other) + : ValueIteratorBase(other) {} + ValueConstIterator& ValueConstIterator:: operator=(const ValueIteratorBase& other) { copy(other); @@ -149,7 +152,9 @@ ValueIterator::ValueIterator(const Value::ObjectValues::iterator& current) : ValueIteratorBase(current) {} ValueIterator::ValueIterator(const ValueConstIterator& other) - : ValueIteratorBase(other) {} + : ValueIteratorBase(other) { + throwRuntimeError("ConstIterator to Iterator should never be allowed."); +} ValueIterator::ValueIterator(const ValueIterator& other) : ValueIteratorBase(other) {} diff --git a/src/test_lib_json/main.cpp b/src/test_lib_json/main.cpp index c6b6721..c1061f4 100644 --- a/src/test_lib_json/main.cpp +++ b/src/test_lib_json/main.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include // Make numeric limits more convenient to talk about. @@ -2436,7 +2435,9 @@ JSONTEST_FIXTURE(IteratorTest, indexes) { JSONTEST_FIXTURE(IteratorTest, const) { Json::Value const v; - Json::Value::iterator it = v.begin(); // This *should not* compile, but does. + JSONTEST_ASSERT_THROWS( + Json::Value::iterator it(v.begin()) // Compile, but throw. + ); Json::Value value;