This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Possible bug in gcc dealing with string class and compiler temps
- To: gcc-bugs at gcc dot gnu dot org
- Subject: Possible bug in gcc dealing with string class and compiler temps
- From: Braxton Thomason <brax at ieeecs dot ece dot utexas dot edu>
- Date: Mon, 14 Feb 2000 11:52:02 -0600 (CST)
- Reply-To: Braxton Thomason <brax at ieeecs dot ece dot utexas dot edu>
Hello,
I believe I have a possible bug in "gcc version 2.95.2 19991024"
running on AIX 4.3.1.0 having to do with the string class and compiler
temporary variables. The attached files duplicate the problem, and also
my attempted work around. The problem is that when I have a class that
contains a string member (mString), and I have a function that does so:
const char & someFunction ( unsigned index ) const { return mString [
index ]; }
gcc generates the compiler warning "returning reference to temporary". I
do not see why this should involve a compiler temp at all, since there is
a method
const_reference operator[](size_type pos) const;
in the string class.
So it seems that it should simply return the appropriate reference.
The attached file haswarning.tar.bz2 has a file main3.C that includes this
short program. I have written a test to see if the compiler is truly
using a temporary variable. This test consists of a short function to
destroy the stack. The output of the program indicates that the compiler
is indeed making use of a temporary variable.
The attached file nowarning.tar.bz2 has my attempted workaround for this
problem. I have changed someFunction to look so:
const char & someFunction ( unsigned index ) const
{ const char & m = mString [ index ]; return m; }
This eliminates the compiler warning, but does not however, fix the
problem. After running main4, the output is still not correct, indicating
that the compiler was still using a temporary.
Please let me know if there is another work around for this, or if there
is anything else that is not clear about this bug report
Thanks for your time,
Sincerely,
Braxton Thomason
haswarning.tar.bz2
nowarning.tar.bz2