public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/16376] New: Bit-field promotions
@ 2004-07-05 21:26 jsm28 at gcc dot gnu dot org
  2004-07-05 21:30 ` [Bug c++/16376] " pinskia at gcc dot gnu dot org
  2004-07-06  9:14 ` rearnsha at gcc dot gnu dot org
  0 siblings, 2 replies; 3+ messages in thread
From: jsm28 at gcc dot gnu dot org @ 2004-07-05 21:26 UTC (permalink / raw)
  To: gcc-bugs

[conv.prom] paragraph 3 says that bit-fields are converted to int by the
integral promotions if int can represent all the values of the bit-field.

The following testcase was discussed on the WG14 reflector in January
as illustrating a difference between C compilers (where an unsigned:3
bit-field has a special 3-bit type, so is promoted to int) and C++ compilers
(where an unsigned:3 bit-field has type unsigned, per [class.bit]), but
[conv.prom] wasn't mentioned in that discussion and as far as I can tell
it means that C++ compilers too should promote the unsigned:3 bit-field to
int.  If not, what's wrong in my reading of [conv.prom]?

#include <stdio.h>

int main(void){
  struct bits {
    unsigned int ui3 : 3;
  } bits;
  int i = -1;   /* is a very large positive number as unsigned */

  bits.ui3 = 1u;
  if( bits.ui3 < i ){
    (void)printf("ui3 treated as unsigned, i promoted to unsigned\n");
  }else{
    (void)printf("ui3 promoted to int (value preserving)\n");
  }
  return 0;
}

My reading of [conv.prom] is that bits.ui3 should have been promoted to int,
though the statistics from the WG14 reflector were that 29 C++ compilers
converted i to unsigned and only 1 promoted bits.ui3 to int.  There are
still differences between C and C++ for bit-fields of types wider than int.

-- 
           Summary: Bit-field promotions
           Product: gcc
           Version: 3.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jsm28 at gcc dot gnu dot org
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16376


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/16376] Bit-field promotions
  2004-07-05 21:26 [Bug c++/16376] New: Bit-field promotions jsm28 at gcc dot gnu dot org
@ 2004-07-05 21:30 ` pinskia at gcc dot gnu dot org
  2004-07-06  9:14 ` rearnsha at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-07-05 21:30 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16376


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/16376] Bit-field promotions
  2004-07-05 21:26 [Bug c++/16376] New: Bit-field promotions jsm28 at gcc dot gnu dot org
  2004-07-05 21:30 ` [Bug c++/16376] " pinskia at gcc dot gnu dot org
@ 2004-07-06  9:14 ` rearnsha at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: rearnsha at gcc dot gnu dot org @ 2004-07-06  9:14 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From rearnsha at gcc dot gnu dot org  2004-07-06 09:14 -------
That was my reading of the C and C++ standards too.

FWIW the ARM C/C++ compiler agrees with you too!

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
   Last reconfirmed|0000-00-00 00:00:00         |2004-07-06 09:14:50
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16376


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-07-06  9:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-07-05 21:26 [Bug c++/16376] New: Bit-field promotions jsm28 at gcc dot gnu dot org
2004-07-05 21:30 ` [Bug c++/16376] " pinskia at gcc dot gnu dot org
2004-07-06  9:14 ` rearnsha at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).