public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/27697]  New: incorrect warning about constness of pointer to an array in a const struct
@ 2006-05-21  9:20 fischer at td dot mw dot tum dot de
  2006-05-21  9:31 ` [Bug c/27697] " fischer at td dot mw dot tum dot de
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: fischer at td dot mw dot tum dot de @ 2006-05-21  9:20 UTC (permalink / raw)
  To: gcc-bugs

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


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

* [Bug c/27697] incorrect warning about constness of pointer to an array in a const struct
  2006-05-21  9:20 [Bug c/27697] New: incorrect warning about constness of pointer to an array in a const struct fischer at td dot mw dot tum dot de
@ 2006-05-21  9:31 ` fischer at td dot mw dot tum dot de
  2006-05-21 16:15 ` [Bug c/27697] [4.0/4.1/4.2 Regression] " pinskia at gcc dot gnu dot org
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: fischer at td dot mw dot tum dot de @ 2006-05-21  9:31 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from fischer at td dot mw dot tum dot de  2006-05-21 09:31 -------
In the function above:

bar.x[0][0] = 23; // gcc 4.1 gives error
*bar.x[0] = 23; // gcc 4.1 gives NO error

both lines do the same ....


-- 


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


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

* [Bug c/27697] [4.0/4.1/4.2 Regression] incorrect warning about constness of pointer to an array in a const struct
  2006-05-21  9:20 [Bug c/27697] New: incorrect warning about constness of pointer to an array in a const struct fischer at td dot mw dot tum dot de
  2006-05-21  9:31 ` [Bug c/27697] " fischer at td dot mw dot tum dot de
@ 2006-05-21 16:15 ` pinskia at gcc dot gnu dot org
  2006-05-21 23:17 ` neil at daikokuya dot co dot uk
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-05-21 16:15 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2006-05-21 16:15 -------
This is also rejects valid with -pedantic-errors.
I don't understand what is correct here so I am not going to confirm it.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic, rejects-valid
      Known to fail|                            |4.0.3 4.1.0 4.2.0
      Known to work|                            |4.0.2
            Summary|incorrect warning about     |[4.0/4.1/4.2 Regression]
                   |constness of pointer to an  |incorrect warning about
                   |array in a const struct     |constness of pointer to an
                   |                            |array in a const struct
   Target Milestone|---                         |4.0.4


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


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

* [Bug c/27697] [4.0/4.1/4.2 Regression] incorrect warning about constness of pointer to an array in a const struct
  2006-05-21  9:20 [Bug c/27697] New: incorrect warning about constness of pointer to an array in a const struct fischer at td dot mw dot tum dot de
  2006-05-21  9:31 ` [Bug c/27697] " fischer at td dot mw dot tum dot de
  2006-05-21 16:15 ` [Bug c/27697] [4.0/4.1/4.2 Regression] " pinskia at gcc dot gnu dot org
@ 2006-05-21 23:17 ` neil at daikokuya dot co dot uk
  2006-05-21 23:53 ` jsm28 at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: neil at daikokuya dot co dot uk @ 2006-05-21 23:17 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from neil at daikokuya dot co dot uk  2006-05-21 23:17 -------
Subject: Re:  [4.0/4.1/4.2 Regression] incorrect warning about constness of
pointer to an array in a const struct

pinskia at gcc dot gnu dot org wrote:-

> 
> 
> ------- Comment #2 from pinskia at gcc dot gnu dot org  2006-05-21 16:15 -------
> This is also rejects valid with -pedantic-errors.
> I don't understand what is correct here so I am not going to confirm it.

If I understand correctly I think the report is correct about
validity for both C90 and C99; another front end gives

"/tmp/bar.c", line 10: error: cannot convert initializer of type "const
        int (*)[10]" to type "int (*)[10]"
  int (*qoox)[10] = bar.x; /* should warn */
                    ^
"/tmp/bar.c", line 11: error: expression must be a modifiable lvalue
  bar.x[0][1] = 23; /* error: asignment to const */
  ^
"/tmp/bar.c", line 9: warning: variable "baz" declared but not used
  const int (*baz)[10] = bar.x; /* should be ok */
              ^

2 errors found compiling "/tmp/bar.c".


-- 


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


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

* [Bug c/27697] [4.0/4.1/4.2 Regression] incorrect warning about constness of pointer to an array in a const struct
  2006-05-21  9:20 [Bug c/27697] New: incorrect warning about constness of pointer to an array in a const struct fischer at td dot mw dot tum dot de
                   ` (2 preceding siblings ...)
  2006-05-21 23:17 ` neil at daikokuya dot co dot uk
@ 2006-05-21 23:53 ` jsm28 at gcc dot gnu dot org
  2006-06-04 19:20 ` mmitchel at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jsm28 at gcc dot gnu dot org @ 2006-05-21 23:53 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from jsm28 at gcc dot gnu dot org  2006-05-21 23:53 -------
Confirmed, my first guess as to a fix would be to make build_component_ref
arrange for the type of the COMPONENT_REF to have the necessary qualifiers via
c_build_qualified_type.


-- 

jsm28 at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
OtherBugsDependingO|                            |16620, 16989
              nThis|                            |
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2006-05-21 23:53:40
               date|                            |


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


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

* [Bug c/27697] [4.0/4.1/4.2 Regression] incorrect warning about constness of pointer to an array in a const struct
  2006-05-21  9:20 [Bug c/27697] New: incorrect warning about constness of pointer to an array in a const struct fischer at td dot mw dot tum dot de
                   ` (3 preceding siblings ...)
  2006-05-21 23:53 ` jsm28 at gcc dot gnu dot org
@ 2006-06-04 19:20 ` mmitchel at gcc dot gnu dot org
  2006-07-17  3:42 ` mmitchel at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2006-06-04 19:20 UTC (permalink / raw)
  To: gcc-bugs



-- 

mmitchel at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P1


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


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

* [Bug c/27697] [4.0/4.1/4.2 Regression] incorrect warning about constness of pointer to an array in a const struct
  2006-05-21  9:20 [Bug c/27697] New: incorrect warning about constness of pointer to an array in a const struct fischer at td dot mw dot tum dot de
                   ` (4 preceding siblings ...)
  2006-06-04 19:20 ` mmitchel at gcc dot gnu dot org
@ 2006-07-17  3:42 ` mmitchel at gcc dot gnu dot org
  2006-08-16 17:18 ` jsm28 at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2006-07-17  3:42 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from mmitchel at gcc dot gnu dot org  2006-07-17 03:42 -------
The trick of using -pedantic-errors to turn every invalid warning into
rejects-valid is not useful.  Downgrading to P2.


-- 

mmitchel at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|rejects-valid               |
           Priority|P1                          |P2


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


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

* [Bug c/27697] [4.0/4.1/4.2 Regression] incorrect warning about constness of pointer to an array in a const struct
  2006-05-21  9:20 [Bug c/27697] New: incorrect warning about constness of pointer to an array in a const struct fischer at td dot mw dot tum dot de
                   ` (5 preceding siblings ...)
  2006-07-17  3:42 ` mmitchel at gcc dot gnu dot org
@ 2006-08-16 17:18 ` jsm28 at gcc dot gnu dot org
  2006-08-16 23:11 ` jsm28 at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jsm28 at gcc dot gnu dot org @ 2006-08-16 17:18 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from jsm28 at gcc dot gnu dot org  2006-08-16 17:17 -------
Testing a patch.


-- 

jsm28 at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |jsm28 at gcc dot gnu dot org
                   |dot org                     |
             Status|NEW                         |ASSIGNED
   Last reconfirmed|2006-05-21 23:53:40         |2006-08-16 17:17:52
               date|                            |


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


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

* [Bug c/27697] [4.0/4.1/4.2 Regression] incorrect warning about constness of pointer to an array in a const struct
  2006-05-21  9:20 [Bug c/27697] New: incorrect warning about constness of pointer to an array in a const struct fischer at td dot mw dot tum dot de
                   ` (6 preceding siblings ...)
  2006-08-16 17:18 ` jsm28 at gcc dot gnu dot org
@ 2006-08-16 23:11 ` jsm28 at gcc dot gnu dot org
  2006-08-16 23:12 ` jsm28 at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jsm28 at gcc dot gnu dot org @ 2006-08-16 23:11 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from jsm28 at gcc dot gnu dot org  2006-08-16 23:10 -------
Subject: Bug 27697

Author: jsm28
Date: Wed Aug 16 23:10:46 2006
New Revision: 116194

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=116194
Log:
        PR c/27697
        * c-typeck.c (build_component_ref): Combine qualifiers of
        structure or union and field.

testsuite:
        * gcc.dg/qual-component-1.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/qual-component-1.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/c-typeck.c
    trunk/gcc/testsuite/ChangeLog


-- 


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


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

* [Bug c/27697] [4.0/4.1/4.2 Regression] incorrect warning about constness of pointer to an array in a const struct
  2006-05-21  9:20 [Bug c/27697] New: incorrect warning about constness of pointer to an array in a const struct fischer at td dot mw dot tum dot de
                   ` (7 preceding siblings ...)
  2006-08-16 23:11 ` jsm28 at gcc dot gnu dot org
@ 2006-08-16 23:12 ` jsm28 at gcc dot gnu dot org
  2006-08-17 13:02 ` [Bug c/27697] [4.0 " brett dot albertson at stratech dot com
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jsm28 at gcc dot gnu dot org @ 2006-08-16 23:12 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from jsm28 at gcc dot gnu dot org  2006-08-16 23:12 -------
Subject: Bug 27697

Author: jsm28
Date: Wed Aug 16 23:12:37 2006
New Revision: 116195

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=116195
Log:
        PR c/27697
        * c-typeck.c (build_component_ref): Combine qualifiers of
        structure or union and field.

testsuite:
        * gcc.dg/qual-component-1.c: New test.

Added:
    branches/gcc-4_1-branch/gcc/testsuite/gcc.dg/qual-component-1.c
      - copied unchanged from r116194,
trunk/gcc/testsuite/gcc.dg/qual-component-1.c
Modified:
    branches/gcc-4_1-branch/gcc/ChangeLog
    branches/gcc-4_1-branch/gcc/c-typeck.c
    branches/gcc-4_1-branch/gcc/testsuite/ChangeLog


-- 


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


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

* [Bug c/27697] [4.0 Regression] incorrect warning about constness of pointer to an array in a const struct
  2006-05-21  9:20 [Bug c/27697] New: incorrect warning about constness of pointer to an array in a const struct fischer at td dot mw dot tum dot de
                   ` (8 preceding siblings ...)
  2006-08-16 23:12 ` jsm28 at gcc dot gnu dot org
@ 2006-08-17 13:02 ` brett dot albertson at stratech dot com
  2006-08-26  0:11 ` jsm28 at gcc dot gnu dot org
  2007-02-03 17:18 ` gdr at gcc dot gnu dot org
  11 siblings, 0 replies; 13+ messages in thread
From: brett dot albertson at stratech dot com @ 2006-08-17 13:02 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from brett dot albertson at stratech dot com  2006-08-17 13:02 -------
(In reply to comment #7)
> Subject: Bug 27697

This fails on i386-pc-solaris2.10 on trunk with:

Executing on host: /u01/var/tmp/gcc_trunk_svn/gcc_20060817/gcc/xgcc
-B/u01/var/tmp/gcc_trunk_svn/gcc_20060817/gcc/
/u01/var/tmp/gcc_trunk_svn/gcc/gcc/testsuite/gcc.dg/qual-component-1.c   
-fno-show-column -S  -o qual-component-1.s    (timeout = 300)
/u01/var/tmp/gcc_trunk_svn/gcc/gcc/testsuite/gcc.dg/qual-component-1.c: In
function 'f':^M
/u01/var/tmp/gcc_trunk_svn/gcc/gcc/testsuite/gcc.dg/qual-component-1.c:45:
error: assignment of read-only member 'd'^M
/u01/var/tmp/gcc_trunk_svn/gcc/gcc/testsuite/gcc.dg/qual-component-1.c:46:
error: assignment of read-only location^M
/u01/var/tmp/gcc_trunk_svn/gcc/gcc/testsuite/gcc.dg/qual-component-1.c:47:
error: assignment of read-only location^M

etc.

and

/u01/var/tmp/gcc_trunk_svn/gcc/gcc/testsuite/gcc.dg/qual-component-1.c: In
function 'g':^M
/u01/var/tmp/gcc_trunk_svn/gcc/gcc/testsuite/gcc.dg/qual-component-1.c:113:
warning: initialization from in compatible pointer type^M
/u01/var/tmp/gcc_trunk_svn/gcc/gcc/testsuite/gcc.dg/qual-component-1.c:118:
warning: assignment from incompatible pointer type^M

etc.

Brett


-- 


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


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

* [Bug c/27697] [4.0 Regression] incorrect warning about constness of pointer to an array in a const struct
  2006-05-21  9:20 [Bug c/27697] New: incorrect warning about constness of pointer to an array in a const struct fischer at td dot mw dot tum dot de
                   ` (9 preceding siblings ...)
  2006-08-17 13:02 ` [Bug c/27697] [4.0 " brett dot albertson at stratech dot com
@ 2006-08-26  0:11 ` jsm28 at gcc dot gnu dot org
  2007-02-03 17:18 ` gdr at gcc dot gnu dot org
  11 siblings, 0 replies; 13+ messages in thread
From: jsm28 at gcc dot gnu dot org @ 2006-08-26  0:11 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from jsm28 at gcc dot gnu dot org  2006-08-26 00:11 -------
Not working on 4.0 fix, as noted at
http://gcc.gnu.org/ml/gcc-patches/2006-08/msg00566.html one test fails there
with the patch applied.


-- 

jsm28 at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|jsm28 at gcc dot gnu dot org|unassigned at gcc dot gnu
                   |                            |dot org
             Status|ASSIGNED                    |NEW


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


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

* [Bug c/27697] [4.0 Regression] incorrect warning about constness of pointer to an array in a const struct
  2006-05-21  9:20 [Bug c/27697] New: incorrect warning about constness of pointer to an array in a const struct fischer at td dot mw dot tum dot de
                   ` (10 preceding siblings ...)
  2006-08-26  0:11 ` jsm28 at gcc dot gnu dot org
@ 2007-02-03 17:18 ` gdr at gcc dot gnu dot org
  11 siblings, 0 replies; 13+ messages in thread
From: gdr at gcc dot gnu dot org @ 2007-02-03 17:18 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #11 from gdr at gcc dot gnu dot org  2007-02-03 17:18 -------
Fixed in GCC-4.1.2.


-- 

gdr at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|4.0.4                       |4.1.2


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


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

end of thread, other threads:[~2007-02-03 17:18 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-05-21  9:20 [Bug c/27697] New: incorrect warning about constness of pointer to an array in a const struct fischer at td dot mw dot tum dot de
2006-05-21  9:31 ` [Bug c/27697] " fischer at td dot mw dot tum dot de
2006-05-21 16:15 ` [Bug c/27697] [4.0/4.1/4.2 Regression] " pinskia at gcc dot gnu dot org
2006-05-21 23:17 ` neil at daikokuya dot co dot uk
2006-05-21 23:53 ` jsm28 at gcc dot gnu dot org
2006-06-04 19:20 ` mmitchel at gcc dot gnu dot org
2006-07-17  3:42 ` mmitchel at gcc dot gnu dot org
2006-08-16 17:18 ` jsm28 at gcc dot gnu dot org
2006-08-16 23:11 ` jsm28 at gcc dot gnu dot org
2006-08-16 23:12 ` jsm28 at gcc dot gnu dot org
2006-08-17 13:02 ` [Bug c/27697] [4.0 " brett dot albertson at stratech dot com
2006-08-26  0:11 ` jsm28 at gcc dot gnu dot org
2007-02-03 17:18 ` gdr 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).