Code Monkey home page Code Monkey logo

Comments (2)

springmeyer avatar springmeyer commented on July 17, 2024

More context:

  • An error like this is also known as a truncating conversion. Is is not undefined behavior, but it is usually unwanted behavior that should be protected from
  • The only current way to detect it is with the -Wconversion warning. However the use of static_cast will silence this warning making it hard to detect (this is why I recommend manual detection and throwing based on numeric_cast).

There is some discussion of adding support for assignment based detection of truncating conversion in clang++: http://clang-developers.42468.n3.nabble.com/A-need-for-an-quot-fsanitize-integer-assign-overflow-quot-td4037252.html#a4037318

Looks like this library might have what we need: https://cs.chromium.org/chromium/src/base/numerics/README.md

Or this one: https://github.com/narizhny/numeric_safety

from carmen-cache.

springmeyer avatar springmeyer commented on July 17, 2024

Closing, since this is more of a discussion piece than actionable. This ticket was created to discuss ways to avoid bugs like #82, but in reality tooling can't really catch all these bugs and unit tests are the way to ensure correct behavior (which we now have for #82).

from carmen-cache.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.