This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c++/8214: GCC does not enforce the left-most "const" in a "const char * const" declaration.
- From: yoavhirsch at yahoo dot com
- To: gcc-gnats at gcc dot gnu dot org
- Date: 13 Oct 2002 20:17:41 -0000
- Subject: c++/8214: GCC does not enforce the left-most "const" in a "const char * const" declaration.
- Reply-to: yoavhirsch at yahoo dot com
>Number: 8214
>Category: c++
>Synopsis: GCC does not enforce the left-most "const" in a "const char * const" declaration.
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: accepts-illegal
>Submitter-Id: net
>Arrival-Date: Sun Oct 13 13:26:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: Yoav Hirsch
>Release: gcc version 3.2
>Organization:
>Environment:
Linux metropolis 2.4.18-3 #1 Thu Apr 18 07:37:53 EDT 2002 i686 unknown
>Description:
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.
>How-To-Repeat:
#include <string>
int main()
{
const char * source = "source";
const char * const target = "target";
std::strcpy(target,source);
return 0;
}
>Fix:
//make the target pointer non-const:
#include <string>
int main()
{
const char * source = "source";
const char * target = "target";
std::strcpy(target,source);
return 0;
}
>Release-Note:
>Audit-Trail:
>Unformatted: