Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#9234 closed Bugs (wontfix)

noexcept creation of a number from string

Reported by: Domagoj Šarić Owned by: John Maddock
Milestone: To Be Determined Component: multiprecision
Version: Boost 1.54.0 Severity: Optimization
Keywords: Cc:

Description

One of the benefits of using fixed-sized numbers is to avoid EH in ones code. It is then a bit 'sad' that one has to pay for EH codegen in the "from char const *" constructor which checks if the passed string is valid...please provide a way to specify to the library that construction will/must succeed (and should be check with an assert, not a throw)...

Change History (2)

comment:1 by John Maddock, 9 years ago

Resolution: wontfix
Status: newclosed

Define BOOST_NO_EXCEPTIONS when building?

In any case, a runtime check is appropriate here, and the cost (yes even of a try/catch block) is likely to be trivially small compared to construction from string in general.

comment:2 by Domagoj Šarić, 9 years ago

  • BOOST_NO_EXCEPTIONS disables exceptions for all Boost, that's not what I want...Exception semantics and overhead maybe appropriate in someplaces while not in others, IMNHO a subset of fixed-sized mathematical operations where I know in advance nothing should fail is one such place


  • the problem with (needless) EH is not (just) speed but bloat, you certainly know that any non-noexcept function makes all of its callers also non-noexcept and inserts EH code in all of them if they have objects with non trivial desctructors (which with MSVC is sadly even an empty but explicitly defined destructor) as well as it hinders things like inlining


  • in my use case for example I might know that I am passing a valid (possibly hardcoded) string and the only way your constructor can fail is if some hacker has fiddled with the binary in which case I don't want any expected error handling route to be taken (a call to throw is certainly one of them)...I really do want the process to visit a random star in the access vioalation galaxy using the undefined behaviour spaceship and then crash and burn there!


  • you might consider using boost::string_ref now to simplify your code

I won't reopen this ticket, I'll rather create a new one for noexcept fixedsized unchecked unsigned cpp_ints...

Note: See TracTickets for help on using tickets.