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: Eli Zaretskii <eliz <at> gnu.org>
To: Dmitry Gutov <dgutov <at> yandex.ru>
Cc: ke.vigouroux <at> laposte.net, eggert <at> cs.ucla.edu, 40671 <at> debbugs.gnu.org, michael_heerdegen <at> web.de, mattiase <at> acm.org, rms <at> gnu.org
Subject: bug#40671: [DOC] modify literal objects
Date: Sun, 26 Apr 2020 17:19:28 +0300
> From: Dmitry Gutov <dgutov <at> yandex.ru>
> Date: Sun, 26 Apr 2020 17:03:38 +0300
> Cc: Michael Heerdegen <michael_heerdegen <at> web.de>, ke.vigouroux <at> laposte.net,
>  40671 <at> debbugs.gnu.org
> 
> > #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"); }

Did you try compiling that as a C program, not a C++ program?

If I force the C compiler to use -Wwrite-strings, then I get:

  gcc -Wwrite-strings string_const.c
  string_const.c: In function 'main':
  string_const.c:2:35: warning: passing argument 1 of 'strcpy' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
   int main (void) { return !strcpy ("a", "b"); }
				     ^~~
  In file included from string_const.c:1:0:
  d:\usr\include\string.h:79:40: note: expected 'char *' but argument is of type 'const char *'
   _CRTIMP __cdecl __MINGW_NOTHROW  char *strcpy (char *, const char *);
					  ^~~~~~

but even that goes away if I modify the program as follows:

  #include <string.h>
  int main (void) { return !strcpy ((char *)"a", "b"); }




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.