FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[SUGGESTION] Add runtime checks for C++ integer division by zero · Issue #1184 · hsutter/cppfront · GitHub

[SUGGESTION] Add runtime checks for C++ integer division by zero #1184

Description

I want to mention this before going ahead:

  • I know that behavior of integer division is dependent on computer architectures and operating system.

As the title suggests, this suggestion is about adding runtime checks on integer division.

Since cpp2 is about safety, I think that defining the exact behavior of this operation will be a good thing to have. (In C++, as per standard, integer division by zero is undefined behavior).

I can think of two ways to "define" what will happen, in case there is integer division by zero at runtime:

  • Throw an exception: This will be a breaking change because operations on built-in data types are not supposed to throw exceptions in C++ (I am unable to find this guarantee written on cppreference, but it was mentioned in Back to Basics: Exception Handling and Exception Safety, 43:49).
  • call std::terminate(), which is consistent with "noexcept" guarantee of built-in data types.

Potential downfalls: This will obviously increase the runtime of program, if the integer division is performed extensively in the program.

The same reasoning is also applicable to integer overflows, but that is a different beast to handle. I am only considering the integer division for this suggestion.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL