This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
g++ 2.95.2 voluntarily creates copies of const char arrays
- To: gcc bug list <gcc-bugs at gcc dot gnu dot org>
- Subject: g++ 2.95.2 voluntarily creates copies of const char arrays
- From: Martin Sebor <sebor at roguewave dot com>
- Date: Thu, 30 Mar 2000 23:12:50 -0700
Hi,
g++ appears to create copies of character arrays when they are being passed to
template functions. It also appears that these copies aren't being deallocated
which is causing memory leaks (reported by our memory leak detection software).
This phenomenon only seems to occur for const character arrays (all forms of
narrow char and wchar_t) initialized with a string literal (i.e., not a braced
initializer list).
We may have already reported this problem but if so, we received no
confirmation.
Thanks
Martin
$ cat test.cpp
template <class T>
const T* foo (const T *t)
{
return t;
}
int main ()
{
const char a[] = "";
return !(a == foo (a));
}
$ g++ test.cpp ; a.out ; echo $?
1