Skip to content

Commit 607b21d

Browse files
committed
default source_location argument for throwing functions
1 parent 36552f0 commit 607b21d

File tree

16 files changed

+63
-138
lines changed

16 files changed

+63
-138
lines changed

include/boost/json/detail/except.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ namespace detail {
2020
BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; \
2121
(ec).assign(e, &loc);
2222

23-
BOOST_JSON_DECL void BOOST_NORETURN throw_bad_alloc(source_location const& loc);
24-
BOOST_JSON_DECL void BOOST_NORETURN throw_invalid_argument(char const* what, source_location const& loc);
25-
BOOST_JSON_DECL void BOOST_NORETURN throw_length_error(char const* what, source_location const& loc);
26-
BOOST_JSON_DECL void BOOST_NORETURN throw_out_of_range(source_location const& loc);
27-
BOOST_JSON_DECL void BOOST_NORETURN throw_system_error(error_code const& ec, source_location const& loc);
23+
BOOST_JSON_DECL void BOOST_NORETURN throw_bad_alloc(source_location const& loc = BOOST_CURRENT_LOCATION);
24+
BOOST_JSON_DECL void BOOST_NORETURN throw_invalid_argument(char const* what, source_location const& loc = BOOST_CURRENT_LOCATION);
25+
BOOST_JSON_DECL void BOOST_NORETURN throw_length_error(char const* what, source_location const& loc = BOOST_CURRENT_LOCATION);
26+
BOOST_JSON_DECL void BOOST_NORETURN throw_out_of_range(source_location const& loc = BOOST_CURRENT_LOCATION);
27+
BOOST_JSON_DECL void BOOST_NORETURN throw_system_error(error_code const& ec, source_location const& loc = BOOST_CURRENT_LOCATION);
2828

2929
} // detail
3030
} // namespace json

include/boost/json/detail/impl/string_impl.ipp

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,7 @@ growth(
121121
std::size_t capacity)
122122
{
123123
if(new_size > max_size())
124-
detail::throw_length_error(
125-
"string too large",
126-
BOOST_CURRENT_LOCATION);
124+
detail::throw_length_error( "string too large" );
127125
// growth factor 2
128126
if( capacity >
129127
max_size() - capacity)
@@ -158,9 +156,7 @@ append(
158156
storage_ptr const& sp)
159157
{
160158
if(n > max_size() - size())
161-
detail::throw_length_error(
162-
"string too large",
163-
BOOST_CURRENT_LOCATION);
159+
detail::throw_length_error( "string too large" );
164160
if(n <= capacity() - size())
165161
{
166162
term(size() + n);
@@ -186,8 +182,7 @@ insert(
186182
{
187183
const auto curr_size = size();
188184
if(pos > curr_size)
189-
detail::throw_out_of_range(
190-
BOOST_CURRENT_LOCATION);
185+
detail::throw_out_of_range();
191186
const auto curr_data = data();
192187
if(n <= capacity() - curr_size)
193188
{
@@ -217,9 +212,7 @@ insert(
217212
else
218213
{
219214
if(n > max_size() - curr_size)
220-
detail::throw_length_error(
221-
"string too large",
222-
BOOST_CURRENT_LOCATION);
215+
detail::throw_length_error( "string too large" );
223216
string_impl tmp(growth(
224217
curr_size + n, capacity()), sp);
225218
tmp.size(curr_size + n);
@@ -249,8 +242,7 @@ insert_unchecked(
249242
{
250243
const auto curr_size = size();
251244
if(pos > curr_size)
252-
detail::throw_out_of_range(
253-
BOOST_CURRENT_LOCATION);
245+
detail::throw_out_of_range();
254246
const auto curr_data = data();
255247
if(n <= capacity() - size())
256248
{
@@ -264,9 +256,7 @@ insert_unchecked(
264256
return dest;
265257
}
266258
if(n > max_size() - curr_size)
267-
detail::throw_length_error(
268-
"string too large",
269-
BOOST_CURRENT_LOCATION);
259+
detail::throw_length_error( "string too large" );
270260
string_impl tmp(growth(
271261
curr_size + n, capacity()), sp);
272262
tmp.size(curr_size + n);
@@ -294,8 +284,7 @@ replace(
294284
{
295285
const auto curr_size = size();
296286
if (pos > curr_size)
297-
detail::throw_out_of_range(
298-
BOOST_CURRENT_LOCATION);
287+
detail::throw_out_of_range();
299288
const auto curr_data = data();
300289
n1 = (std::min)(n1, curr_size - pos);
301290
const auto delta = (std::max)(n1, n2) -
@@ -343,9 +332,7 @@ replace(
343332
else
344333
{
345334
if (delta > max_size() - curr_size)
346-
detail::throw_length_error(
347-
"string too large",
348-
BOOST_CURRENT_LOCATION);
335+
detail::throw_length_error( "string too large" );
349336
// would exceed capacity, reallocate
350337
string_impl tmp(growth(
351338
curr_size + delta, capacity()), sp);
@@ -379,8 +366,7 @@ replace_unchecked(
379366
{
380367
const auto curr_size = size();
381368
if(pos > curr_size)
382-
detail::throw_out_of_range(
383-
BOOST_CURRENT_LOCATION);
369+
detail::throw_out_of_range();
384370
const auto curr_data = data();
385371
const auto delta = (std::max)(n1, n2) -
386372
(std::min)(n1, n2);
@@ -401,9 +387,7 @@ replace_unchecked(
401387
return replace_pos;
402388
}
403389
if(delta > max_size() - curr_size)
404-
detail::throw_length_error(
405-
"string too large",
406-
BOOST_CURRENT_LOCATION);
390+
detail::throw_length_error( "string too large" );
407391
// would exceed capacity, reallocate
408392
string_impl tmp(growth(
409393
curr_size + delta, capacity()), sp);

include/boost/json/detail/value_to.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -300,13 +300,13 @@ value_to_impl(
300300
if( !obj )
301301
{
302302
BOOST_JSON_FAIL(ec, error::not_object);
303-
throw_system_error(ec, BOOST_CURRENT_LOCATION);
303+
throw_system_error( ec );
304304
}
305305

306306
T result;
307307
ec = detail::try_reserve(result, obj->size(), reserve_implementation<T>());
308308
if( ec.failed() )
309-
throw_system_error(ec, BOOST_CURRENT_LOCATION);
309+
throw_system_error( ec );
310310

311311
auto ins = detail::inserter(result, inserter_implementation<T>());
312312
for( key_value_pair const& kv: *obj )
@@ -362,13 +362,13 @@ value_to_impl(
362362
if( !arr )
363363
{
364364
BOOST_JSON_FAIL(ec, error::not_array);
365-
throw_system_error(ec, BOOST_CURRENT_LOCATION);
365+
throw_system_error( ec );
366366
}
367367

368368
T result;
369369
ec = detail::try_reserve(result, arr->size(), reserve_implementation<T>());
370370
if( ec.failed() )
371-
throw_system_error(ec, BOOST_CURRENT_LOCATION);
371+
throw_system_error( ec );
372372

373373
auto ins = detail::inserter(result, inserter_implementation<T>());
374374
for( value const& val: *arr )
@@ -452,14 +452,14 @@ value_to_impl(
452452
if( !arr )
453453
{
454454
BOOST_JSON_FAIL(ec, error::not_array);
455-
throw_system_error(ec, BOOST_CURRENT_LOCATION);
455+
throw_system_error( ec );
456456
}
457457

458458
constexpr std::size_t N = std::tuple_size<remove_cvref<T>>::value;
459459
if( N != arr->size() )
460460
{
461461
BOOST_JSON_FAIL(ec, error::size_mismatch);
462-
throw_system_error(ec, BOOST_CURRENT_LOCATION);
462+
throw_system_error( ec );
463463
}
464464

465465
return make_tuple_like<T>(
@@ -627,7 +627,7 @@ value_to_impl(
627627
{
628628
auto res = tag_invoke(try_value_to_tag<T>(), jv);
629629
if( res.has_error() )
630-
throw_system_error(res.error(), BOOST_CURRENT_LOCATION);
630+
throw_system_error( res.error() );
631631
return std::move(*res);
632632
}
633633

include/boost/json/impl/array.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,7 @@ array::
207207
at(std::size_t pos) &
208208
{
209209
if(pos >= t_->size)
210-
detail::throw_out_of_range(
211-
BOOST_CURRENT_LOCATION);
210+
detail::throw_out_of_range();
212211
return (*t_)[pos];
213212
}
214213

@@ -224,8 +223,7 @@ array::
224223
at(std::size_t pos) const&
225224
{
226225
if(pos >= t_->size)
227-
detail::throw_out_of_range(
228-
BOOST_CURRENT_LOCATION);
226+
detail::throw_out_of_range();
229227
return (*t_)[pos];
230228
}
231229

include/boost/json/impl/array.ipp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ allocate(
4040
{
4141
BOOST_ASSERT(capacity > 0);
4242
if(capacity > array::max_size())
43-
detail::throw_length_error(
44-
"array too large",
45-
BOOST_CURRENT_LOCATION);
43+
detail::throw_length_error( "array too large" );
4644
auto p = reinterpret_cast<
4745
table*>(sp->allocate(
4846
sizeof(table) +
@@ -100,9 +98,7 @@ revert_insert(
10098
return;
10199
}
102100
if(n_ > max_size() - arr_->size())
103-
detail::throw_length_error(
104-
"array too large",
105-
BOOST_CURRENT_LOCATION);
101+
detail::throw_length_error( "array too large" );
106102
auto t = table::allocate(
107103
arr_->growth(arr_->size() + n_),
108104
arr_->sp_);
@@ -626,9 +622,7 @@ growth(
626622
std::size_t new_size) const
627623
{
628624
if(new_size > max_size())
629-
detail::throw_length_error(
630-
"array too large",
631-
BOOST_CURRENT_LOCATION);
625+
detail::throw_length_error( "array too large" );
632626
std::size_t const old = capacity();
633627
if(old > max_size() - old / 2)
634628
return new_size;

include/boost/json/impl/null_resource.ipp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ protected:
6666
std::size_t,
6767
std::size_t) override
6868
{
69-
detail::throw_bad_alloc(
70-
BOOST_CURRENT_LOCATION);
69+
detail::throw_bad_alloc();
7170
}
7271

7372
void

include/boost/json/impl/object.hpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,7 @@ at(string_view key) & ->
342342
{
343343
auto it = find(key);
344344
if(it == end())
345-
detail::throw_out_of_range(
346-
BOOST_CURRENT_LOCATION);
345+
detail::throw_out_of_range();
347346
return it->value();
348347
}
349348

@@ -362,8 +361,7 @@ at(string_view key) const& ->
362361
{
363362
auto it = find(key);
364363
if(it == end())
365-
detail::throw_out_of_range(
366-
BOOST_CURRENT_LOCATION);
364+
detail::throw_out_of_range();
367365
return it->value();
368366
}
369367

@@ -499,9 +497,7 @@ insert(
499497
std::distance(first, last));
500498
auto const n0 = size();
501499
if(n > max_size() - n0)
502-
detail::throw_length_error(
503-
"object too large",
504-
BOOST_CURRENT_LOCATION);
500+
detail::throw_length_error( "object too large" );
505501
reserve(n0 + n);
506502
revert_insert r(*this);
507503
while(first != last)

include/boost/json/impl/object.ipp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -448,9 +448,7 @@ insert(
448448
{
449449
auto const n0 = size();
450450
if(init.size() > max_size() - n0)
451-
detail::throw_length_error(
452-
"object too large",
453-
BOOST_CURRENT_LOCATION);
451+
detail::throw_length_error( "object too large" );
454452
reserve(n0 + init.size());
455453
revert_insert r(*this);
456454
if(t_->is_small())
@@ -786,9 +784,7 @@ growth(
786784
std::size_t new_size) const
787785
{
788786
if(new_size > max_size())
789-
detail::throw_length_error(
790-
"object too large",
791-
BOOST_CURRENT_LOCATION);
787+
detail::throw_length_error( "object too large" );
792788
std::size_t const old = capacity();
793789
if(old > max_size() - old / 2)
794790
return new_size;

include/boost/json/impl/parse.ipp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ parse(
6060
auto jv = parse(
6161
s, ec, std::move(sp), opt);
6262
if(ec)
63-
detail::throw_system_error(ec,
64-
BOOST_CURRENT_LOCATION);
63+
detail::throw_system_error( ec );
6564
return jv;
6665
}
6766

@@ -127,8 +126,7 @@ parse(
127126
auto jv = parse(
128127
is, ec, std::move(sp), opt);
129128
if(ec)
130-
detail::throw_system_error(ec,
131-
BOOST_CURRENT_LOCATION);
129+
detail::throw_system_error( ec );
132130
return jv;
133131
}
134132

include/boost/json/impl/parser.ipp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ write_some(
9292
auto const n = write_some(
9393
data, size, ec);
9494
if(ec)
95-
detail::throw_system_error(ec,
96-
BOOST_CURRENT_LOCATION);
95+
detail::throw_system_error( ec );
9796
return n;
9897
}
9998

@@ -137,8 +136,7 @@ write(
137136
auto const n = write(
138137
data, size, ec);
139138
if(ec)
140-
detail::throw_system_error(ec,
141-
BOOST_CURRENT_LOCATION);
139+
detail::throw_system_error( ec );
142140
return n;
143141
}
144142

@@ -156,8 +154,7 @@ release()
156154
p_.fail(ec);
157155
}
158156
detail::throw_system_error(
159-
p_.last_error(),
160-
BOOST_CURRENT_LOCATION);
157+
p_.last_error());
161158
}
162159
return p_.handler().st.release();
163160
}

0 commit comments

Comments
 (0)