User account creation filtered due to spam.

Bug 8214 - [3.2/3.3 regression] character conversion problem
Summary: [3.2/3.3 regression] character conversion problem
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.2
: P3 normal
Target Milestone: ---
Assignee: Mark Mitchell
URL:
Keywords: accepts-invalid
Depends on:
Blocks:
 
Reported: 2002-10-13 13:26 UTC by yoavhirsch
Modified: 2003-07-25 17:33 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description yoavhirsch 2002-10-13 13:26:00 UTC
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;
}
Comment 1 yoavhirsch 2002-10-13 13:26:00 UTC
Fix:
http://gcc.gnu.org/ml/gcc-patches/2002-11/msg01979.html
Comment 2 Wolfgang Bangerth 2002-11-22 11:36:51 UTC
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
Comment 3 Mark Mitchell 2002-11-30 13:48:15 UTC
Responsible-Changed-From-To: unassigned->mmitchel
Responsible-Changed-Why: Working on a fix.
Comment 4 Mark Mitchell 2002-11-30 20:01:22 UTC
State-Changed-From-To: analyzed->closed
State-Changed-Why: Fixed in G++ 3.3.
Comment 5 Mark Mitchell 2002-12-01 02:11:06 UTC
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
 

Comment 6 Mark Mitchell 2002-12-01 02:11:06 UTC
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
 
Comment 7 Mark Mitchell 2002-12-01 03:58:53 UTC
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
 

Comment 8 Mark Mitchell 2002-12-01 03:58:53 UTC
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