Article View: gnu.gcc.bug
Article #6242Bug Report (String literals not constant).
From: Ian Greenhoe
Date: Thu, 21 Dec 1995 00:00
Date: Thu, 21 Dec 1995 00:00
90 lines
2779 bytes
2779 bytes
The bug is that the compiler should be reporting a
"assignment of read-only location" at line 5 of test.cc (provided below)
whenever '-fwritable-strings' (or something that invokes it) is not
present. I have tried explicitly using '-fno-writable-strings' to
no effect.
Line 5 of test.cc is the line that reads:
"abcd"[2] = 'x';
I believe the problem is that the compiler is treating string literals
as being of type (char *) regardless of command-line options.
Machine name and compiler output are in gcc.runtime.info .
Test program is in test.cc .
Compiler preprocessor output is in test.out.cc .
Configuration file for compiler make ( config.status ) is in config.status.
No changes were made to the compiler.
Compiler was installed by "make -install".
IHG
-------- begin gcc.runtime.info --------
mercury% uname -a
HP-UX mercury B.10.00 A 9000/770
mercury% gcc -v
Reading specs from /usr/local/lib/gcc-lib/hppa1.1-hp-hpux10.00/2.7.2/specs
gcc version 2.7.2
mercury% gcc -g -I/usr/local/include/g++ -I/usr/local/include test.cc -c
test.cc: In function `void test2()':
test.cc:10: assignment of read-only location
mercury% gcc -g -I/usr/local/include/g++ -I/usr/local/include test.cc -c -fno-writable-strings
test.cc: In function `void test2()':
test.cc:10: assignment of read-only location
mercury% gcc -g -I/usr/local/include/g++ -I/usr/local/include test.cc -c -fwritable-strings
test.cc: In function `void test2()':
test.cc:10: assignment of read-only location
mercury% gcc -g -I/usr/local/include/g++ -I/usr/local/include test.cc -E > test.cc.out
mercury%
-------- end gcc.runtime.info --------
-------- begin test.cc --------
// Testing constant strings.
void test1 ()
{
"abcd"[2] = 'x';
}
void test2 ()
{
((const char *) "abcd")[2] = 'x';
}
-------- end test.cc --------
-------- begin test.cc.out --------
# 1 "test.cc"
void test1 ()
{
"abcd"[2] = 'x';
}
void test2 ()
{
((const char *) "abcd")[2] = 'x';
}
-------- end test.cc.out --------
-------- begin config.status --------
#!/bin/sh
# GCC was configured as follows:
./configure --with-gcc --with-gnu-as
echo host=hppa1.1-hp-hpux10.00 target=hppa1.1-hp-hpux10.00 build=hppa1.1-hp-hpux
10.00
--------- end config.status --------
Technical Details
Message-ID:
<9512212358.AA27852@life.ai.mit.edu>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 113d02,6633cb2f038c6a37,start X-Google-Attributes: gid113d02,public From: greenman@mercury.apl.washington.edu (Ian Greenhoe) Subject: Bug Report (String literals not constant). Date: 1995/12/21 Message-ID: <9512212358.AA27852@life.ai.mit.edu> X-Deja-AN: 122600011 distribution: gnu sender: daemon@cis.ohio-state.edu organization: GNUs Not Usenet newsgroups: gnu.gcc.bug