bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#40671: [DOC] modify literal objects


From: Dmitry Gutov
Subject: bug#40671: [DOC] modify literal objects
Date: Sun, 26 Apr 2020 17:03:38 +0300
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1

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.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]