When compiling a piece of C-source code, like:

#include <stdio.h>

void doit(char *p)
{
        p[0] = 'y';
        printf("doit: %s\n", p);
}

int main(void)
{
        const char *str = "hello there";

        /* check whether gcc complains about const qualifier. The
-Werror=ignored-qualifiers did not work (unfortunatelly) */
        doit(str);

        return 0;
}

with:
gcc-4.3 -o constchar  -Wall -Werror=ignored-qualifiers constchar.c

The following (correct) warning is raised:

constchar.c:16: warning: passing argument 1 of 'doit' discards qualifiers from
pointer target type

However, this warning can't be disabled with -Wno-ignored-qualifiers or turned
into an error with -Werror=ignored-qualifiers. 

The latter one is the one is most wanted by me. It would be useful if the
compiler becomes more strict in handling const char *, which could point to
read-only memory.

Involved versions:
gcc-4.3 -v
Using built-in specs.
Target: x86_64-suse-linux
Configured with: ../configure --prefix=/usr --infodir=/usr/share/info
--mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64
--enable-languages=c,c++,objc,fortran,obj-c++,java,ada
--enable-checking=release --with-gxx-include-dir=/usr/include/c++/4.3
--enable-ssp --disable-libssp --with-bugurl=http://bugs.opensuse.org/
--with-pkgversion='SUSE Linux' --disable-libgcj --disable-libmudflap
--with-slibdir=/lib64 --with-system-zlib --enable-__cxa_atexit
--enable-libstdcxx-allocator=new --disable-libstdcxx-pch
--enable-version-specific-runtime-libs --program-suffix=-4.3
--enable-linux-futex --without-system-libunwind --with-cpu=generic
--build=x86_64-suse-linux
Thread model: posix
gcc version 4.3.3 [gcc-4_3-branch revision 147732] (SUSE Linux) 


uname -a
Linux nlbaldev2 2.6.16.60-0.21-smp #1 SMP Tue May 6 12:41:02 UTC 2008 x86_64
x86_64 x86_64 GNU/Linux

cat /etc/SuSE-release 
SUSE Linux Enterprise Server 10 (x86_64)
VERSION = 10
PATCHLEVEL = 2


-- 
           Summary: discarding const char * qualifiers cannot be disabled or
                    turned into an error
           Product: gcc
           Version: 4.3.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: kees dot dekker at infor dot com


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

Reply via email to