https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78473
Bug ID: 78473 Summary: Enhancement request: __builtin_div_overflow Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: webrown.cpp at gmail dot com Target Milestone: --- https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html documents gcc intrinsic functions to perform integer arithmetic with overflow checking. Addition, subtraction, and multiplication are supported, but division is not. However, division can overflow, for any of at least three different reasons: (1) For a signed 2s-complement integer type T, consider dividing the most negative value by T(-1); the result can't be represented in T. (2) There are also cases involving mixed types such that the quotient can't be represented in the smaller type or in a too-small third type. (3) There's also the always-delightful division by zero opportunity. I am therefore writing to request that division be supported as a future enhancement to current functionality. Both the __builtin_*div_overflow and __builtin_div_overflow_p forms would be useful, IMO. It also seems useful to support a remainder operation in some manner, either as a separate set of functions or perhaps via extra arguments to the division functions. Thanks very much.