Library: some coverage for rejected type placements
The `SeveralBuilder` is very flexible with respect to added elements, but it will investigate the provided type information and reject any further build operation that can not be carried out safely.
This commit is contained in:
parent
1169b6272e
commit
006809712e
3 changed files with 59 additions and 10 deletions
|
|
@ -540,13 +540,15 @@ namespace lib {
|
|||
|
||||
template<typename TY>
|
||||
void
|
||||
__ensureMark (DestructionMethod expectedKind)
|
||||
__ensureMark (DestructionMethod requiredKind)
|
||||
{
|
||||
if (destructor != UNKNOWN and destructor != expectedKind)
|
||||
throw err::Invalid{_Fmt{"Unable to handle destructor for element type %s, "
|
||||
"since this container has been primed to use %s-deleters."}
|
||||
% util::typeStr<TY>() % render(expectedKind)};
|
||||
destructor = expectedKind;
|
||||
if (destructor != UNKNOWN and destructor != requiredKind)
|
||||
throw err::Invalid{_Fmt{"Unable to handle (%s-)destructor for element type %s, "
|
||||
"since this container has been primed to use %s-destructors."}
|
||||
% render(requiredKind)
|
||||
% util::typeStr<TY>()
|
||||
% render(destructor)};
|
||||
destructor = requiredKind;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -134,7 +134,14 @@ namespace test{
|
|||
}
|
||||
|
||||
|
||||
/** @test TODO various ways to build an populate the container
|
||||
/** @test various ways to build an populate the container
|
||||
* - with a defined interface type \a I, instances of arbitrary subclasses
|
||||
* can be added, assuming there is sufficient pre-allocated buffer space;
|
||||
* all these subclass instances are accessed through the common interface.
|
||||
* - yet the added elements can also be totally unrelated, in which case an
|
||||
* *unchecked wild cast* will happen on access; while certainly dangerous,
|
||||
* this behaviour allows for special low-level data layout tricks.
|
||||
* - the results from an iterator can be used to populate by copy
|
||||
* @todo WIP 6/24 🔁 define ⟶ ✔ implement
|
||||
*/
|
||||
void
|
||||
|
|
@ -204,6 +211,43 @@ namespace test{
|
|||
void
|
||||
check_ErrorHandling()
|
||||
{
|
||||
{ // Scenario-1 : Baseclass and arbitrary subclass elements
|
||||
SeveralBuilder<Dummy> builder;
|
||||
|
||||
// The first element will _prime_ the container for a suitable usage pattern
|
||||
builder.emplace<Num<1>>();
|
||||
CHECK (1 == builder.size());
|
||||
|
||||
// Notably the first element established the _spread_ between index positions,
|
||||
// which effectively limits the size of objects to be added. Moreover, since
|
||||
// the element type was detected to be non-trivial, we can not correct this
|
||||
// element spacing by shifting existing allocations (`memmove()` not possible)
|
||||
CHECK (sizeof(Num<1>) < sizeof(Num<5>));
|
||||
VERIFY_FAIL ("Unable to place element of type Num<5u> (size="
|
||||
, builder.emplace<Num<5>>() );
|
||||
CHECK (1 == builder.size());
|
||||
|
||||
// Furthermore, the first element was detected to be a subclass,
|
||||
// and the interface type `Dummy` has a virtual destructor;
|
||||
// all added elements must comply to this scheme, once established
|
||||
VERIFY_FAIL ("Unable to handle (trivial-)destructor for element type long, "
|
||||
"since this container has been primed to use virtual-baseclass-destructors."
|
||||
, builder.emplace<long>(55) );
|
||||
CHECK (1 == builder.size());
|
||||
|
||||
// the initial allocation added some reserve buffer space (for 10 elements)
|
||||
// and we can fill that space with arbitrary subclass instances
|
||||
builder.fillElm (5);
|
||||
CHECK (6 == builder.size());
|
||||
|
||||
// But the initial allocation can not be increased, since that would require
|
||||
// a re-allocation of a larger buffer, followed by copying the elements;
|
||||
// but since the established scheme allows for _arbitrary_ subclasses,
|
||||
// the builder does not know the exact type for safe element relocation.
|
||||
VERIFY_FAIL ("Unable to accommodate further element of type Dummy"
|
||||
, builder.fillElm (20) );
|
||||
CHECK (10 == builder.size());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -83369,9 +83369,11 @@ Date:   Thu Apr 20 18:53:17 2023 +0200<br/>
|
|||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1716857382441" ID="ID_610081580" MODIFIED="1716857402102" TEXT="check_ErrorHandling">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node CREATED="1718121991093" ID="ID_70431031" MODIFIED="1718121997497" TEXT="Base + beliebiger Typ">
|
||||
<node CREATED="1718121998540" ID="ID_160009328" MODIFIED="1718122009540" TEXT="Typ zu groß"/>
|
||||
<node CREATED="1718122010547" ID="ID_1757791910" MODIFIED="1718122019981" TEXT="nicht genügend Storage und kann nicht verschieben"/>
|
||||
<node COLOR="#338800" CREATED="1718121991093" ID="ID_70431031" MODIFIED="1718153132386" TEXT="Base + beliebiger Typ">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
<node COLOR="#435e98" CREATED="1718121998540" ID="ID_160009328" MODIFIED="1718153130346" STYLE="fork" TEXT="Typ zu groß"/>
|
||||
<node COLOR="#435e98" CREATED="1718153109115" ID="ID_443086499" MODIFIED="1718153130346" STYLE="fork" TEXT="kein Typ mit anderem nicht-passenden Destruktor-Schema"/>
|
||||
<node COLOR="#435e98" CREATED="1718122010547" ID="ID_1757791910" MODIFIED="1718153130345" STYLE="fork" TEXT="nicht genügend Storage und kann nicht verschieben"/>
|
||||
</node>
|
||||
<node CREATED="1718122030712" ID="ID_1960968889" MODIFIED="1718122040234" TEXT="Base + bekanntes E">
|
||||
<node CREATED="1718122066531" ID="ID_1633309056" MODIFIED="1718122076582" TEXT="kann wachsen (da move-ctor bekannt)"/>
|
||||
|
|
@ -83380,6 +83382,7 @@ Date:   Thu Apr 20 18:53:17 2023 +0200<br/>
|
|||
<node CREATED="1718122252659" ID="ID_616405505" MODIFIED="1718122291873" TEXT="Triviale Typen">
|
||||
<node CREATED="1718122293022" ID="ID_697520417" MODIFIED="1718122302248" TEXT="kann wachsen"/>
|
||||
<node CREATED="1718122302932" ID="ID_293207594" MODIFIED="1718122311738" TEXT="kann spread ändern"/>
|
||||
<node CREATED="1718153752253" ID="ID_1509145683" MODIFIED="1718153763392" TEXT="kann aber keinen nicht-trivialen Typ platzieren"/>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1716857382441" ID="ID_1397767362" MODIFIED="1716857402102" TEXT="check_ElementAccess">
|
||||
|
|
|
|||
Loading…
Reference in a new issue