This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/27697] New: incorrect warning about constness of pointer to an array in a const struct


In this snippet of code:

struct foo {
  int x[2][10];
};

void f(void)
{
  const struct foo bar;
  const int (*baz)[10] = bar.x; /* should be ok */
  int (*qoox)[10] = bar.x; /* should warn */

  bar.x[0][1] = 23; /* error: asignment to const */
  (*qoox)[1] = 23;
}

bar is const, so bar.x is (const int *), so an assignment to (const int *)
should be ok, while an assignment to (int *) violates the type constraints (all
according to 6.7.3 in the Standard).

in gcc 4.1.0, the behaviour is reversed: assignment to (int *) goes unnoticed
while assignment to (const int *) issues an "incompatible pointer" warning.


-- 
           Summary: incorrect warning about constness of pointer to an array
                    in a const struct
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: fischer at td dot mw dot tum dot de
 GCC build triplet: i586-suse-linux
  GCC host triplet: i586-suse-linux
GCC target triplet: i586-suse-linux


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]