GNU bug report logs - #40671
[DOC] modify literal objects

Previous Next

Package: emacs;

Reported by: Kevin Vigouroux <ke.vigouroux <at> laposte.net>

Date: Thu, 16 Apr 2020 20:40:02 UTC

Severity: normal

Tags: patch

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Dmitry Gutov <dgutov <at> yandex.ru>
To: Paul Eggert <eggert <at> cs.ucla.edu>, Mattias Engdegård <mattiase <at> acm.org>, Richard Stallman <rms <at> gnu.org>
Cc: Michael Heerdegen <michael_heerdegen <at> web.de>, ke.vigouroux <at> laposte.net, 40671 <at> debbugs.gnu.org
Subject: bug#40671: [DOC] modify literal objects
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.




This bug report was last modified 5 years and 2 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.