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]

g++ 2.95.2 voluntarily creates copies of const char arrays


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

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