Skip to content

[ub:expr.mul.div.by.zero] Code comment does not agree with normative wording #9341

Open

Description

@cpplearner

[ub:expr.mul.div.by.zero]:

int main() {
  int x = 1 / 0;        // undefined behavior, division by zero
  double d = 1.0 / 0.0; // undefined behavior on systems where the range of
                        // representable values of double is [-max,+max], on systems where
                        // representable values is [-inf,+inf] this would not be undefined behavior
}

The normative wording is ([expr.mul]/4):

If the second operand of / or % is zero, the behavior is undefined ([ub:expr.mul.div.by.zero]).

That is, the behavior of 1.0 / 0.0 is undefined even on systems that have positive and negative infinity.

In addition, a note in [expr.pre]/4 (added by P3899R3 "Clarify the behavior of floating-point overflow") mentions:

If the operands are of a type that adheres to ISO/IEC 60559, division by zero is the only case where an arithmetic expression has undefined behavior ([expr.mul]).

Activity

  1. eisenwave commented on Sep 21, 2026

    @eisenwave
    Member
  2. added
    ub-ifndr
    on Sep 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ub-ifndr

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions