Skip to content
18 changes: 9 additions & 9 deletions include/boost/json/basic_parser_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ parse_comment(const char* p,
st_.pop(st);
switch(st)
{
default: BOOST_JSON_UNREACHABLE();
default: BOOST_JSON_UNREACHABLE(); // LCOV_EXCL_LINE
case state::com1: goto do_com1;
case state::com2: goto do_com2;
case state::com3: goto do_com3;
Expand Down Expand Up @@ -723,7 +723,7 @@ resume_value(const char* p,
st_.peek(st);
switch(st)
{
default: BOOST_JSON_UNREACHABLE();
default: BOOST_JSON_UNREACHABLE(); // LCOV_EXCL_LINE
case state::lit1:
return parse_literal(p, detail::literals_c<detail::literals::resume>() );

Expand Down Expand Up @@ -859,7 +859,7 @@ parse_literal(const char* p, Literal)
}
else
{
BOOST_JSON_UNREACHABLE();
BOOST_JSON_UNREACHABLE(); // LCOV_EXCL_LINE
}

cs += sz;
Expand Down Expand Up @@ -947,7 +947,7 @@ parse_literal(const char* p, Literal)
ec_)))
return fail(cs.begin());
break;
default: BOOST_JSON_UNREACHABLE();
default: BOOST_JSON_UNREACHABLE(); // LCOV_EXCL_LINE
}

cs += size;
Expand Down Expand Up @@ -977,7 +977,7 @@ parse_string(const char* p,
st_.pop(total);
switch(st)
{
default: BOOST_JSON_UNREACHABLE();
default: BOOST_JSON_UNREACHABLE(); // LCOV_EXCL_LINE
case state::str2: goto do_str2;
case state::str8: goto do_str8;
case state::str1: break;
Expand Down Expand Up @@ -1191,7 +1191,7 @@ parse_escaped(
st_.pop(st);
switch(st)
{
default: BOOST_JSON_UNREACHABLE();
default: BOOST_JSON_UNREACHABLE(); // LCOV_EXCL_LINE
case state::str3: goto do_str3;
case state::str4: goto do_str4;
case state::str5: goto do_str5;
Expand Down Expand Up @@ -1739,7 +1739,7 @@ parse_object(const char* p,
st_.pop(size);
switch(st)
{
default: BOOST_JSON_UNREACHABLE();
default: BOOST_JSON_UNREACHABLE(); // LCOV_EXCL_LINE
case state::obj1: goto do_obj1;
case state::obj2: goto do_obj2;
case state::obj3: goto do_obj3;
Expand Down Expand Up @@ -1908,7 +1908,7 @@ parse_array(const char* p,
st_.pop(size);
switch(st)
{
default: BOOST_JSON_UNREACHABLE();
default: BOOST_JSON_UNREACHABLE(); // LCOV_EXCL_LINE
case state::arr1: goto do_arr1;
case state::arr2: goto do_arr2;
case state::arr3: goto do_arr3;
Expand Down Expand Up @@ -2158,7 +2158,7 @@ parse_number(const char* p,
st_.pop(st);
switch(st)
{
default: BOOST_JSON_UNREACHABLE();
default: BOOST_JSON_UNREACHABLE(); // LCOV_EXCL_LINE
case state::num1: goto do_num1;
case state::num2: goto do_num2;
case state::num3: goto do_num3;
Expand Down
3 changes: 1 addition & 2 deletions include/boost/json/detail/impl/default_resource.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ default_resource::instance_;
// this is here so that ~memory_resource
// is emitted in the library instead of
// the user's TU.
default_resource::
~default_resource() = default;
default_resource::~default_resource() = default; // LCOV_EXCL_LINE

void*
default_resource::
Expand Down
4 changes: 2 additions & 2 deletions include/boost/json/impl/parse.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ parse(
value result = parse(s, jec, std::move(sp), opt);
ec = jec;
return result;
}
} // LCOV_EXCL_LINE

value
parse(
Expand Down Expand Up @@ -114,7 +114,7 @@ parse(
value result = parse(is, jec, std::move(sp), opt);
ec = jec;
return result;
}
} // LCOV_EXCL_LINE

value
parse(
Expand Down
27 changes: 8 additions & 19 deletions include/boost/json/impl/value.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -225,30 +225,19 @@ value(
//
//----------------------------------------------------------

value::
value(
std::initializer_list<value_ref> init,
storage_ptr sp)
value::value(std::initializer_list<value_ref> init, storage_ptr sp)
{
if(value_ref::maybe_object(init))
if( value_ref::maybe_object(init) )
{
::new(&obj_) object(
value_ref::make_object(
init, std::move(sp)));
::new(&obj_) object( value_ref::make_object(init, std::move(sp)) );
}
else if( init.size() == 1 )
{
::new(this) value( init.begin()->make_value(std::move(sp)) );
}
else
{
if( init.size() == 1 )
{
::new(this) value(
init.begin()->make_value( std::move(sp) ));
}
else
{
::new(&arr_) array(
value_ref::make_array(
init, std::move(sp)));
}
::new(&arr_) array( value_ref::make_array(init, std::move(sp)) );
}
}

Expand Down
16 changes: 2 additions & 14 deletions include/boost/json/impl/value_ref.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,6 @@ value() const
return make_value({});
}

value
value_ref::
from_init_list(
void const* p,
storage_ptr sp)
{
return make_value(
*reinterpret_cast<
init_list const*>(p),
std::move(sp));
}

bool
value_ref::
is_key_value_pair() const noexcept
Expand Down Expand Up @@ -97,11 +85,11 @@ make_value(
case what::func:
return f_.f(f_.p,
std::move(sp));

case what::strfunc:
return f_.f(f_.p,
std::move(sp));

case what::cfunc:
return cf_.f(cf_.p,
std::move(sp));
Expand Down
2 changes: 1 addition & 1 deletion include/boost/json/value_from.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ value_from(
value jv(std::move(sp));
value_from( static_cast<T&&>(t), ctx, jv );
return jv;
}
} // LCOV_EXCL_LINE

/// Overload
template<class T>
Expand Down
7 changes: 0 additions & 7 deletions include/boost/json/value_ref.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,13 +431,6 @@ class value_ref
void* p,
storage_ptr sp);

static
BOOST_JSON_DECL
value
from_init_list(
void const* p,
storage_ptr sp);

inline
bool
is_key_value_pair() const noexcept;
Expand Down
59 changes: 58 additions & 1 deletion test/basic_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,8 +594,8 @@ class basic_parser_test
TEST_GOOD("1000000000000000000000000.000000000001");
TEST_GOOD("1000000000000000000000000.0e1 ");
TEST_GOOD("1000000000000000000000000.0 ");

TEST_GOOD("1000000000.1000000000 ");
TEST_GOOD("100000000000000000000e+2147483647");

TEST_BAD("");
TEST_BAD("- ");
Expand Down Expand Up @@ -1387,6 +1387,7 @@ class basic_parser_test
TEST_BAD("\"\xf1\x7f\xbf\xbf----------\"");
TEST_BAD("\"\xf2\x80\x7f\xbf----------\"");
TEST_BAD("\"\xf3\x80\xbf\xce----------\"");
TEST_BAD("\"\xf3\x80\xbf");

// utf8 after escape
TEST_GOOD("\"\\u0000 \xf3\xbf\x80\xbf\xf3\xbf\x80\xbf\"");
Expand Down Expand Up @@ -1752,6 +1753,60 @@ class basic_parser_test
#pragma warning(pop)
#endif

struct null_handler
{
constexpr static std::size_t max_object_size = std::size_t(-1);
constexpr static std::size_t max_array_size = std::size_t(-1);
constexpr static std::size_t max_key_size = std::size_t(-1);
constexpr static std::size_t max_string_size = std::size_t(-1);

bool on_document_begin( system::error_code& ) { return true; }
bool on_document_end( system::error_code& ) { return true; }
bool on_object_begin( system::error_code& ) { return true; }
bool on_object_end( std::size_t, system::error_code& ) { return true; }
bool on_array_begin( system::error_code& ) { return true; }
bool on_array_end( std::size_t, system::error_code& ) { return true; }
bool on_key_part( string_view, std::size_t, system::error_code& ) { return true; }
bool on_key( string_view, std::size_t, system::error_code& ) { return true; }
bool on_string_part( string_view, std::size_t, system::error_code& ) { return true; }
bool on_string( string_view, std::size_t, system::error_code& ) { return true; }
bool on_number_part( string_view, system::error_code&) { return true; }
bool on_int64( std::int64_t, string_view, system::error_code& ) { return true; }
bool on_uint64( std::uint64_t, string_view, system::error_code& ) { return true; }
bool on_double( double, string_view, system::error_code& ) { return true; }
bool on_bool( bool, system::error_code& ) { return true; }
bool on_null( system::error_code& ) { return true; }
bool on_comment_part( string_view, system::error_code& ) { return true; }
bool on_comment( string_view, system::error_code& ) { return true; }
};

void
testManualFail()
{
basic_parser<null_handler> p({});
p.fail( system::error_code() );
BOOST_TEST( !p.done() );
BOOST_TEST( p.last_error() == error::incomplete );
BOOST_TEST( p.last_error().has_location() );

p.reset();

system::error_code ec;
p.write_some(false, "null", 4, ec);
BOOST_TEST( p.done() );
p.fail( make_error_code(error::array_too_large) );
BOOST_TEST( !p.done() );
BOOST_TEST( p.last_error() == error::array_too_large );
}

void
testWhitespace()
{
parse_options opts;
opts.allow_comments = true;
TEST_BAD_EXT("//\n ", opts);
}

void
run()
{
Expand All @@ -1776,6 +1831,8 @@ class basic_parser_test
testNumberLiteral();
testStickyErrors();
testStdTypes();
testManualFail();
testWhitespace();
}
};

Expand Down
Loading
Loading