dcleblanc / SafeInt

SafeInt is a class library for C++ that manages integer overflows.
MIT License
202 stars 37 forks source link

SafeInt: Annotate return values with [[nodiscard]] when possible. #34

Closed bgianfo closed 2 years ago

bgianfo commented 3 years ago

Annotating return values instructs the compiler to flag callers who do not properly observe the return value. This is intended to find cases of misuse of the SafeInt API.

Closes: #33

dcleblanc commented 3 years ago

Sorry about late response. If I'm not mistaken, Visual Studio has the same sort of annotation, so if I'm going to do that, I should do it evenly. If so, I need to see when they started supporting this, and whether some non-standard version preceded it.

I also have to think about whether this needs to be used in what are internal methods not exposed externally. It is possible it might find a bug in some future change, but the only place I am sure it should be are on the non-throwing methods.

Also, older compilers might lie about this attribute, so that needs some testing. I encountered that sort of thing with constexpr.

I do agree that this needs to get done.

dcleblanc commented 3 years ago

I've investigated this a little, and despite the fact that the [[]] syntax has been in the standard for some time, apparently, Visual Studio has to be compiled with the C++17 standard for it to work. Which means that I now need to test with that scenario, and detect that standard version. This isn't huge amounts of work, just a little more than I expected. I'll try to fix this soon.