left_n_bits(0) invokes undefined behavior

XMLWordPrintable

    • b14
    • generic
    • generic

      The current definition of left_n_bits is

      #define left_n_bits(n) \
        (right_n_bits(n) << (((n) >= BitsPerWord) ? 0 : (BitsPerWord - (n))))

      When n == 0, this reduces to

        (right_n_bits(0) << BitsPerWord)

      According to C++03 5.8/2, the behavior of a shift expression is undefined if the right operand is greater than or equal to the length in bits of the promoted left operand. So a shift by BitsPerWord invokes undefined behavior.

            Assignee:
            Harold Seigel (Inactive)
            Reporter:
            Kim Barrett
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: