GCC correctly gives an error when trying to strcpy into a "const char *" pointer. But GCC incorrectly allows a strcpy into a "const char * const" pointer as shown in the code below. Release: gcc version 3.2 Environment: Linux metropolis 2.4.18-3 #1 Thu Apr 18 07:37:53 EDT 2002 i686 unknown How-To-Repeat: #include <string> int main() { const char * source = "source"; const char * const target = "target"; std::strcpy(target,source); return 0; }
Fix: http://gcc.gnu.org/ml/gcc-patches/2002-11/msg01979.html
State-Changed-From-To: open->analyzed State-Changed-Why: Confirmed. This used to give an error with 2.95, but does no more. It is thus a regression. The code in question is ------------------------- void foo(char *dest); int main() { const char * const p = "abc"; foo (p); } ------------------------------ The thing is weird, because if p is not initialized by "abc" but with a null pointer, then gcc correctly gives an error... tmp/g> /home/bangerth/bin/gcc-3.3y-pre/bin/c++ -c x.cc tmp/g> /home/bangerth/bin/gcc-3.2.1-pre/bin/c++ -c x.cc tmp/g> c++ -c x.cc x.cc: In function `int main()': x.cc:5: passing `const char *const' as argument 1 of `foo(char *)' discards qualifiers
Responsible-Changed-From-To: unassigned->mmitchel Responsible-Changed-Why: Working on a fix.
State-Changed-From-To: analyzed->closed State-Changed-Why: Fixed in G++ 3.3.
From: mmitchel@gcc.gnu.org To: gcc-gnats@gcc.gnu.org Cc: Subject: c++/8214 Date: 1 Dec 2002 02:11:06 -0000 CVSROOT: /cvs/gcc Module name: gcc Changes by: mmitchel@gcc.gnu.org 2002-11-30 18:11:06 Modified files: gcc/testsuite : ChangeLog gcc/cp : ChangeLog typeck.c Added files: gcc/testsuite/g++.dg/init: string1.C Log message: PR c++/8214 * g++.dg/init/string1.C: New test. PR c++/8214 * typeck.c (convert_for_assignment): Do not use decl_constant_value on the operand. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.2240&r2=1.2241 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/init/string1.C.diff?cvsroot=gcc&r1=NONE&r2=1.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.3058&r2=1.3059 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/typeck.c.diff?cvsroot=gcc&r1=1.434&r2=1.435
From: mmitchel@gcc.gnu.org To: gcc-gnats@gcc.gnu.org Cc: Subject: c++/8214 Date: 1 Dec 2002 03:58:53 -0000 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_2-branch Changes by: mmitchel@gcc.gnu.org 2002-11-30 19:58:53 Modified files: gcc/testsuite : ChangeLog gcc/cp : ChangeLog typeck.c Added files: gcc/testsuite/g++.dg/init: string1.C Log message: PR c++/8214 * g++.dg/init/string1.C: New test. PR c++/8214 * typeck.c (convert_for_assignment): Do not use decl_constant_value on the operand. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.1672.2.166.2.59&r2=1.1672.2.166.2.60 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/init/string1.C.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=NONE&r2=1.1.2.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.2685.2.114.2.44&r2=1.2685.2.114.2.45 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/typeck.c.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.388.2.10.2.2&r2=1.388.2.10.2.3