Uploaded image for project: 'Embedded Software & Tools'
  1. Embedded Software & Tools
  2. EXT_EP-11008

Should issue diagnostic when assigning integer constant to a bit-field too small to represent the value

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: Not Prioritized Not Prioritized

      The compiler should emit a warning that an integer conversion resulted in truncation when assigning an integer constant to a bit-field that is too small to hold the integer value. The compiler does not emit a warning when the declared type of the bit-field is big enough to hold the integer value, even though the actual bit-field might be too small to represent the value.

      #include <stdint.h>
      
      struct
      {
          uint32_t hi:16;
          uint32_t lo:16;
      } s;
      
      void foo()
      {
          uint16_t l  = 0x10000U;
          s.lo = 0x10000U; /* should get the same warning, but doesn't */
      }
      

            syncuser TI User
            syncuser TI User
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: