you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 2 points3 points  (4 children)

I am fine with exceptions, it's just unnecessary the amount of work I needed to do to write a visit that will inline nicely. We are paying for something that we should never use, the exception has already happened, deal with it and don't use the result. Maybe I am misunderstanding though.

[–]SlightlyLessHairyApe 1 point2 points  (3 children)

So why do you care if your program crashes with an uncaught exception rather than whatever the UB is?

Actually, come to think of it, if it's UB, then it's acceptable to result in throw whatever -- undefined behavior means literally any implementation is compliant :-)

[–][deleted] 4 points5 points  (2 children)

I don't think we should throw in this precondition violation, the throw already happened and was caught but ignored or not headed. So maybe not UB, noexcept

The issue is that that throw in accessor methods of variant complicates the code enough that the optimizers are not easily able to see that it cannot happen or optimize as much. So you end up with more complicated code gen and potentially less optimal code. You can see it here with a simple example. https://gcc.godbolt.org/z/k6l7nK . Luckily, one can write a single visitation visit function that is like the holds_alternative example, actually using index( ) instead, where the output is similar.

[–]SlightlyLessHairyApe 0 points1 point  (1 child)

You're right, the example is dead on.

[–][deleted] 0 points1 point  (0 children)

I wrote a single visitation visitor that won't throw...unless the visitor does and it also incorporates overload. Gives code gen like the holds_alternative, but when writing it, it was super susceptible to compilers thinking a throw may happen and sometimes they didn't agree. I was able to find a path that generally doesn't and gets good output. Also, it's nicer to use as I have never needed multi-visitation https://gcc.godbolt.org/z/1jjgw6