Skip to content

Commit 984d714

Browse files
committed
Change tests to use direct initialization (value-init once)
1 parent 64048d3 commit 984d714

File tree

1 file changed

+53
-41
lines changed

1 file changed

+53
-41
lines changed

test/scope.t.cpp

Lines changed: 53 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -280,13 +280,21 @@ CASE( "unique_resource: a successfully acquired resource is deleted" )
280280
// scope:
281281
{
282282
#if scope_USE_POST_CPP98_VERSION
283-
auto cr = make_unique_resource_checked(
283+
# if !scope_BETWEEN(scope_COMPILER_MSVC_VERSION, 100, 120)
284+
// Use value initialization once here, direct initialization furtheron:
285+
286+
auto cr{ make_unique_resource_checked(
284287
Resource::open( true ), Resource::invalid(), Amp(Resource::close)
285-
);
288+
)};
289+
# else
290+
auto cr( make_unique_resource_checked(
291+
Resource::open( true ), Resource::invalid(), Amp(Resource::close)
292+
));
293+
# endif
286294
#else
287-
unique_resource<size_t, void(*)(size_t)> cr = make_unique_resource_checked(
295+
unique_resource<size_t, void(*)(size_t)> cr( make_unique_resource_checked(
288296
Resource::open( true ), Resource::invalid(), Amp(Resource::close)
289-
);
297+
));
290298
#endif
291299
EXPECT( Resource::is_acquired() );
292300
}
@@ -299,35 +307,35 @@ CASE( "unique_resource: an unsuccessfully acquired resource is not deleted" )
299307
// scope:
300308
{
301309
#if scope_USE_POST_CPP98_VERSION
302-
auto cr = make_unique_resource_checked(
310+
auto cr( make_unique_resource_checked(
303311
Resource::open( false ), Resource::invalid(), Amp(Resource::close)
304-
);
312+
));
305313
#else
306-
unique_resource<size_t, void(*)(size_t)> cr = make_unique_resource_checked(
314+
unique_resource<size_t, void(*)(size_t)> cr( make_unique_resource_checked(
307315
Resource::open( false ), Resource::invalid(), Amp(Resource::close)
308-
);
316+
));
309317
#endif
310318
EXPECT_NOT( Resource::is_acquired() );
311319
}
312320

313321
EXPECT_NOT( Resource::is_deleted() );
314322
}
315323

316-
CASE( "unique_resource: op=() replaces the managed resouce and the deleter with the give one's" )
324+
CASE( "unique_resource: op=() replaces the managed resouce and the deleter with the give one's" " [move-assignment]" )
317325
{
318326
size_t r1;
319327
size_t r2;
320328

321329
// scope:
322330
{
323331
#if scope_USE_POST_CPP98_VERSION
324-
auto cr1 = make_unique_resource_checked(
332+
auto cr1( make_unique_resource_checked(
325333
Resource::open( true ), Resource::invalid(), Amp(Resource::close)
326-
);
334+
));
327335
#else
328-
unique_resource<size_t, void(*)(size_t)> cr1 = make_unique_resource_checked(
336+
unique_resource<size_t, void(*)(size_t)> cr1( make_unique_resource_checked(
329337
Resource::open( true ), Resource::invalid(), Amp(Resource::close)
330-
);
338+
));
331339
#endif
332340
r1 = cr1.get();
333341

@@ -349,13 +357,13 @@ CASE( "unique_resource: reset() executes deleter" )
349357
// scope:
350358
{
351359
#if scope_USE_POST_CPP98_VERSION
352-
auto cr = make_unique_resource_checked(
360+
auto cr( make_unique_resource_checked(
353361
Resource::open( true ), Resource::invalid(), Amp(Resource::close)
354-
);
362+
));
355363
#else
356-
unique_resource<size_t, void(*)(size_t)> cr = make_unique_resource_checked(
364+
unique_resource<size_t, void(*)(size_t)> cr( make_unique_resource_checked(
357365
Resource::open( true ), Resource::invalid(), Amp(Resource::close)
358-
);
366+
));
359367
#endif
360368
cr.reset();
361369

@@ -373,13 +381,13 @@ CASE( "unique_resource: reset(resource) deletes original resource and replaces i
373381
// scope:
374382
{
375383
#if scope_USE_POST_CPP98_VERSION
376-
auto cr1 = make_unique_resource_checked(
384+
auto cr1( make_unique_resource_checked(
377385
Resource::open( true ), Resource::invalid(), Amp(Resource::close)
378-
);
386+
));
379387
#else
380-
unique_resource<size_t, void(*)(size_t)> cr1 = make_unique_resource_checked(
388+
unique_resource<size_t, void(*)(size_t)> cr1( make_unique_resource_checked(
381389
Resource::open( true ), Resource::invalid(), Amp(Resource::close)
382-
);
390+
));
383391
#endif
384392
r1 = cr1.get();
385393
r2 = Resource::open( true );
@@ -398,13 +406,13 @@ CASE( "unique_resource: release() releases the ownership and prevents execution
398406
// scope:
399407
{
400408
#if scope_USE_POST_CPP98_VERSION
401-
auto cr = make_unique_resource_checked(
409+
auto cr( make_unique_resource_checked(
402410
Resource::open( true ), Resource::invalid(), Amp(Resource::close)
403-
);
411+
));
404412
#else
405-
unique_resource<size_t, void(*)(size_t)> cr = make_unique_resource_checked(
413+
unique_resource<size_t, void(*)(size_t)> cr( make_unique_resource_checked(
406414
Resource::open( true ), Resource::invalid(), Amp(Resource::close)
407-
);
415+
));
408416
#endif
409417
cr.release();
410418

@@ -419,13 +427,13 @@ CASE( "unique_resource: get() provides the underlying resource handle" )
419427
size_t r = Resource::open( true );
420428

421429
#if scope_USE_POST_CPP98_VERSION
422-
auto cr = make_unique_resource_checked(
430+
auto cr( make_unique_resource_checked(
423431
r, Resource::invalid(), Amp(Resource::close)
424-
);
432+
));
425433
#else
426-
unique_resource<size_t, void(*)(size_t)> cr = make_unique_resource_checked(
434+
unique_resource<size_t, void(*)(size_t)> cr( make_unique_resource_checked(
427435
r, Resource::invalid(), Amp(Resource::close)
428-
);
436+
));
429437
#endif
430438

431439
EXPECT( cr.get() == r );
@@ -434,13 +442,13 @@ CASE( "unique_resource: get() provides the underlying resource handle" )
434442
CASE( "unique_resource: get_deleter() provides the deleter used for disposing of the managed resource" )
435443
{
436444
#if scope_USE_POST_CPP98_VERSION
437-
auto cr = make_unique_resource_checked(
445+
auto cr( make_unique_resource_checked(
438446
Resource::open( true ), Resource::invalid(), Amp(Resource::close)
439-
);
447+
));
440448
#else
441-
unique_resource<size_t, void(*)(size_t)> cr = make_unique_resource_checked(
449+
unique_resource<size_t, void(*)(size_t)> cr( make_unique_resource_checked(
442450
Resource::open( true ), Resource::invalid(), Amp(Resource::close)
443-
);
451+
));
444452
#endif
445453

446454
// note: lest does not support op=( T (*)(...), T (*)(...) ):
@@ -455,13 +463,13 @@ CASE( "unique_resource: op*() provides the pointee if the resource handle is a p
455463
int i = 77;
456464

457465
#if scope_USE_POST_CPP98_VERSION
458-
auto cr = make_unique_resource_checked(
466+
auto cr( make_unique_resource_checked(
459467
&i, nullptr, Amp(no::op)
460-
);
468+
));
461469
#else
462-
unique_resource<int *, void(*)(int const *)> cr = make_unique_resource_checked(
470+
unique_resource<int *, void(*)(int const *)> cr( make_unique_resource_checked(
463471
&i, (int *)0, Amp(no::op)
464-
);
472+
));
465473
#endif
466474

467475
EXPECT( *cr == 77 );
@@ -474,14 +482,18 @@ CASE( "unique_resource: op->() provides the pointee if the resource handle is a
474482
struct no { static void op( S const * ){} };
475483

476484
#if scope_USE_POST_CPP98_VERSION
477-
auto cr = make_unique_resource_checked(
485+
auto cr( make_unique_resource_checked(
478486
&s, nullptr, Amp(no::op)
479-
);
487+
));
480488
#else
481-
unique_resource<S *, void(*)(S const *)> cr = make_unique_resource_checked(
489+
unique_resource<S *, void(*)(S const *)> cr( make_unique_resource_checked(
482490
&s, (S *)0, Amp(no::op)
483-
);
491+
));
484492
#endif
485493

486494
EXPECT( cr->i == 77 );
487495
}
496+
497+
CASE( "unique_resource: " "[move-construction][on-deleter-throws]")
498+
{
499+
}

0 commit comments

Comments
 (0)