https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83347

            Bug ID: 83347
           Summary: write pointer to const string possible without warning
           Product: gcc
           Version: 6.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: aleks at physik dot tu-berlin.de
  Target Milestone: ---

It is possible to get a writeable pointer to a const "string".
Point 3 and 4 give an error or warning (as they should),
but point 1 and 2 should at least give a warning. 
Point 1 gives a pointer that is violating the const-qualifiers.
Point 1+2 cause undefined behavior, but no warning is shown.

I don't see any use-case where wrinting to a "const string" is a good idea.
If this is really allowed, then it should be discussed.

1.  char * p = "TEST"; // no warning or error (NOK)
2.  memcpy("abc","def",3); // no warning or error (NOK)
3.  const char * cp = 0; char * p2 = cp; // -Wdiscarded-qualifiers (OK)
4.  "test" = "w"; // error: assignment to expression with array type (OK)

tested on gcc (GCC) 6.4.0 under Cygwin(MinGW).

Thanks for answer, Alex

Reply via email to