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]

c++/8214: GCC does not enforce the left-most "const" in a "const char * const" declaration.


>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:


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