public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/35235]  New: struct/union rvalue qualifiers must not propagate to members
@ 2008-02-17 17:15 truedfx at gentoo dot org
  2008-02-17 23:15 ` [Bug c/35235] " jsm28 at gcc dot gnu dot org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: truedfx at gentoo dot org @ 2008-02-17 17:15 UTC (permalink / raw)
  To: gcc-bugs

Hi,

This turns out to be a strictly conforming C99 program:

#include <stdlib.h>
int main(void) {
    const struct {
        int array[1];
    } s;
    // int *from_lvalue = s.array; // #1
    int *from_rvalue = (rand() ? s : s).array; // #2
}

#1, if uncommented, should be rejected with -std=c99 -pedantic-errors, and
quite rightly is. However, in #2, the result of the conditional expression is
not an lvalue. C99 6.7.3p3 states that type qualifiers are not meaningful for
non-lvalues. Because of that, the type of (rand() ? s : s).array is int[1], not
const int[1], and it converts to int*, not const int*. This means the
initialization should be allowed, even though there is nothing you are allowed
to do with from_rvalue afterwards. It is certainly true that this code is
complete rubbish, and this handling by gcc should not cause any problems in any
real-world code, but technically, it's a bug, so I'm reporting it here.

The code is rejected in gcc 4.1 (4.1.2), 4.2 (4.2.2) and 4.3 (4.3-20080208). It
used to be accepted in older versions (3.3.6, 3.4.6, 4.0.4), but in those older
versions, no warning was given even for #1. Because of that, I'm not sure if
this qualifies as a regression.


-- 
           Summary: struct/union rvalue qualifiers must not propagate to
                    members
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: truedfx at gentoo dot org


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


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

end of thread, other threads:[~2009-03-30  1:29 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-17 17:15 [Bug c/35235] New: struct/union rvalue qualifiers must not propagate to members truedfx at gentoo dot org
2008-02-17 23:15 ` [Bug c/35235] " jsm28 at gcc dot gnu dot org
2008-07-04 19:31 ` [Bug c/35235] [4.2/4.3/4.4 Regression] " jsm28 at gcc dot gnu dot org
2009-02-04 17:15 ` jsm28 at gcc dot gnu dot org
2009-02-04 21:03 ` jsm28 at gcc dot gnu dot org
2009-03-30  1:26 ` [Bug c/35235] [4.2/4.3/4.4/4.5 " jsm28 at gcc dot gnu dot org
2009-03-30  1:29 ` jsm28 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).