File tree 3 files changed +9
-3
lines changed 3 files changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -400,8 +400,8 @@ Json::Value obj_value(Json::objectValue); // {}
400
400
// / otherwise, false.
401
401
bool empty () const ;
402
402
403
- // / Return isNull()
404
- bool operator ! () const ;
403
+ // / Return ! isNull()
404
+ explicit operator bool () const ;
405
405
406
406
// / Remove all object members and array elements.
407
407
// / \pre type() is arrayValue, objectValue, or nullValue
Original file line number Diff line number Diff line change @@ -962,7 +962,7 @@ bool Value::empty() const {
962
962
return false ;
963
963
}
964
964
965
- bool Value::operator ! () const { return isNull (); }
965
+ Value::operator bool () const { return ! isNull (); }
966
966
967
967
void Value::clear () {
968
968
JSON_ASSERT_MESSAGE (type_ == nullValue || type_ == arrayValue ||
Original file line number Diff line number Diff line change @@ -308,6 +308,12 @@ JSONTEST_FIXTURE(ValueTest, null) {
308
308
JSONTEST_ASSERT_STRING_EQUAL (" " , null_.asString ());
309
309
310
310
JSONTEST_ASSERT_EQUAL (Json::Value::null, null_);
311
+
312
+ // Test using a Value in a boolean context (false iff null)
313
+ JSONTEST_ASSERT_EQUAL (null_,false );
314
+ JSONTEST_ASSERT_EQUAL (object1_,true );
315
+ JSONTEST_ASSERT_EQUAL (!null_,true );
316
+ JSONTEST_ASSERT_EQUAL (!object1_,false );
311
317
}
312
318
313
319
JSONTEST_FIXTURE (ValueTest, strings) {
You can’t perform that action at this time.
0 commit comments