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/64825] New: -Wcast-qual does not warn about struct members which are arrays


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64825

            Bug ID: 64825
           Summary: -Wcast-qual does not warn about struct members which
                    are arrays
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dimitry at andric dot com

I'm not sure if it is intentional in gcc, but when using -Wcast-qual, it does
not warn about casting away the constness of struct members which are arrays.

For example, in this minimal test case:

struct foo {
        int bar[1];
};

void *baz(const struct foo *f)
{
        void *p = (void *)&f->bar;
        return p;
}

Compiled with gcc version 5.0.0 20150111 (experimental) (FreeBSD Ports
Collection), using -Wcast-qual, this gives no warning at all.

Compiled with clang version 3.6.0 (branches/release_36 226102), using
-Wcast-qual, gives the expected:

foo.c:7:20: warning: cast from 'int const (*)[1]' to 'void *' drops const
qualifier [-Wcast-qual]
        void *p = (void *)&f->bar;
                          ^
1 warning generated.


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