public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/37560]  New: bitfield not promoted to int
@ 2008-09-17 14:35 clemens at ladisch dot de
  2008-09-17 14:52 ` [Bug c/37560] " joseph at codesourcery dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: clemens at ladisch dot de @ 2008-09-17 14:35 UTC (permalink / raw)
  To: gcc-bugs

In the following program, the type of the assignment expression "f.x = 1"
should be int, according to the integer promotion rules.
However, gcc 4.xx (on all architectures I've tested) prints "1".


#include <stdio.h>
int main()
{
        struct foo { int x:1; } f;
        printf("%u\n", sizeof(f.x = 1));
        return 0;
}


-- 
           Summary: bitfield not promoted to int
           Product: gcc
           Version: 4.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: clemens at ladisch dot de
GCC target triplet: x86_64-suse-linux


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


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

* [Bug c/37560] bitfield not promoted to int
  2008-09-17 14:35 [Bug c/37560] New: bitfield not promoted to int clemens at ladisch dot de
@ 2008-09-17 14:52 ` joseph at codesourcery dot com
  2008-09-17 15:12 ` clemens at ladisch dot de
  2008-09-17 15:56 ` joseph at codesourcery dot com
  2 siblings, 0 replies; 4+ messages in thread
From: joseph at codesourcery dot com @ 2008-09-17 14:52 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from joseph at codesourcery dot com  2008-09-17 14:50 -------
Subject: Re:   New: bitfield not promoted to int

On Wed, 17 Sep 2008, clemens at ladisch dot de wrote:

> In the following program, the type of the assignment expression "f.x = 1"
> should be int, according to the integer promotion rules.
> However, gcc 4.xx (on all architectures I've tested) prints "1".

Why do you think the type should be int instead of int:1?  The conclusion 
from C90 DRs was that bit-fields have their own types, and from C99 DRs 
was to leave whether they have their own types implementation-defined, and 
GCC follows the C90 DRs and so the assignment has type int:1 and is not 
promoted as an operand of sizeof.

Now, for C++ you have a valid bug report, since there bit-fields do not 
have their own types, and the reported behavior appears for C++ as well.


-- 


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


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

* [Bug c/37560] bitfield not promoted to int
  2008-09-17 14:35 [Bug c/37560] New: bitfield not promoted to int clemens at ladisch dot de
  2008-09-17 14:52 ` [Bug c/37560] " joseph at codesourcery dot com
@ 2008-09-17 15:12 ` clemens at ladisch dot de
  2008-09-17 15:56 ` joseph at codesourcery dot com
  2 siblings, 0 replies; 4+ messages in thread
From: clemens at ladisch dot de @ 2008-09-17 15:12 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from clemens at ladisch dot de  2008-09-17 15:11 -------
According to the proposed TC in DR 315 ("If an int can represent all values of
the original type (as restricted by the width, for a bit-field), the type is
converted to an int;"), 


-- 

clemens at ladisch dot de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


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

* [Bug c/37560] bitfield not promoted to int
  2008-09-17 14:35 [Bug c/37560] New: bitfield not promoted to int clemens at ladisch dot de
  2008-09-17 14:52 ` [Bug c/37560] " joseph at codesourcery dot com
  2008-09-17 15:12 ` clemens at ladisch dot de
@ 2008-09-17 15:56 ` joseph at codesourcery dot com
  2 siblings, 0 replies; 4+ messages in thread
From: joseph at codesourcery dot com @ 2008-09-17 15:56 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from joseph at codesourcery dot com  2008-09-17 15:55 -------
Subject: Re:  bitfield not promoted to int

On Wed, 17 Sep 2008, clemens at ladisch dot de wrote:

> According to the proposed TC in DR 315 ("If an int can represent all values of
> the original type (as restricted by the width, for a bit-field), the type is
> converted to an int;"), 

That's part of the integer promotions, which are only applied in certain 
contexts (and the operand of sizeof is not one of those contexts).


-- 


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


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

end of thread, other threads:[~2008-09-17 15:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-09-17 14:35 [Bug c/37560] New: bitfield not promoted to int clemens at ladisch dot de
2008-09-17 14:52 ` [Bug c/37560] " joseph at codesourcery dot com
2008-09-17 15:12 ` clemens at ladisch dot de
2008-09-17 15:56 ` joseph at codesourcery dot com

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).