Subject: Re: bug#40671: [DOC] modify literal objects

From: Dmitry Gutov <[email-masked]>
Date: Sun, 26 Apr 2020 17:03:38 +0300

On 26.04.2020 06:49, Paul Eggert wrote:
>> Might succeed? Will it even compile?
> Yes, although the C/C++ program must type-check and satisfy all other static
> constraints of course (otherwise it won't compile). Here's a simple example:
> 
> #include <string.h>
> int main (void) { return !strcpy ("a", "b"); }
> 
> This function attempts to modify the "a" string constant, so it might dump core,
> or might return 0, or might do other things.

g++ string_const.c++
string_const.c++: In function ‘int main()’:
string_const.c++:2:35: warning: ISO C++ forbids converting a string 
constant to ‘char*’ [-Wwrite-strings]
     2 | int main (void) { return !strcpy ("a", "b"); }

I have no idea why it only shows a compile-time warning (probably 
because of backward-compatibility concerns because in C a string is 
*not* a const, just a source of undefined behavior), but the warning, at 
least, is there for the user to see. Not just in the manual.