g++ 2.95.2 voluntarily creates copies of const char arrays

Martin Sebor sebor@roguewave.com
Thu Mar 30 22:07:00 GMT 2000


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


More information about the Gcc-bugs mailing list