I've been working on evolving some code down in my project's foundation to
enable to user visible improvements. My stategy involves the C++ standard
library facility variant
which allows the user to stores a single
value at any given time but from multiple different types. For those of you with
the proper background this is an improved union
.1 It
also provides some basic infrastructure for the situation when it does not hold
a value at all, and I've been diligently covering my a all the
bases as I go along.
Now I want to test so aspects of the work I've done so far.
Testing the "variant is in a bad, bad place" code means making a variant in a bad, bad place. Only it turns out that is not at all easy.2 There isn't a facility to make one. Not brand new to made-to-order, nor from an existing one by any usual means. cpp reference says
A variant may become valueless in the following situations:and it includs a sample of code to do the job, and a link to an online platform to compiler and run and see that it does the job. Now that code uses a custom type so I can't use it directly, but where I try to ape it using one of the types in my variant ... it doesn't work. I'm able write code that will hit all the last three conditions, but apparently my compiler is too smart for that.
- (guaranteed) an exception is thrown during the initialization of the contained value during move assignment
- (optionally) an exception is thrown during the initialization of the contained value during copy assignment
- (optionally) an exception is thrown when initializing the contained value during a type-changing assignment
- (optionally) an exception is thrown when initializing the contained value during a type-changing emplace
Well, given how hard it is to access that state maybe testing the code that handles is houldn't be a high priority, but I"m annoyed.
1 Nor is it anything like a new idea, but it wasn't made part of the C++ standard library until the 2017 standard. Thankfully, by project has moved that far forward in time.
2 Of course this is a good thing. Except that it isn't quite impossible, so there is all that infrastructure there for handling the special case. Argh!
No comments:
Post a Comment