This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Wart in string constant handling, gcc 2.95.2


  On my system (detailed info to follow), this compiles as c++ code:
strcpy("test", "test");
  but this does not:
strcpy(foo() ? "test" : "test", "test")

  This seems surprising enough to merit a bug report... I couldn't find
any mention of similar behavior on gcc.gnu.org, and my understanding of
const char *s is that both of these should be illegal.  Can you offer
any enlightenment?  Standard apologies if I've overlooked something
obvious, in which case I'd appreciate a pointer to information about
this.

-- begin detailed information

  I'm running gcc 2.95.2 on a Pentium Linux system.  gcc -v tells me:

Reading specs from /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/specs
gcc version 2.95.2 19991024 (release)

  My Linux is a vanilla Mandrake 7.0 distro without any compiler
modifications.  The following file:

#include <string.h>

main() {
  strcpy("test", "test");
  strcpy(strlen("a") ? "test" : "test", "test");
  return 0;
}

  produces the following output when compiled ("gcc test.cc", no arguments):

test.cc: In function `int main()':
test.cc:5: passing `const char *' as argument 1 of `strcpy(char *, const
char *)' discards qualifiers

  whereas commenting out the line with the ?/: produces an executable,
albeit one that seg faults when it tries to write to string-constant
memory. 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]