在 2025-10-20 00:10, Yan-Jie Wang 写道:
On Sun, Oct 19, 2025 at 10:04 PM Yan-Jie Wang <[email protected]> wrote:+ str=new(::std::nothrow) char[mbSize];It seems that ConvertBSTRToString calls `operator new[](size_t)` to allocate memory rather than calling the nothrow version.
By default, the nothrow overload invokes the throwing one and catches all exceptions, much like what you did in the first patch. In this code:
#include <stdlib.h>
#include <stdio.h>
#include <new>
void*
operator new(::size_t n)
{
void* p = ::malloc(n);
::printf("operator new(%zd) = %p\n", n, p);
return p;
}
void
operator delete(void* p)
noexcept
{
if(!p) return;
::printf("operator delete(%p)\n", p);
::free(p);
}
int
main(void)
{
int* test_p = new(::std::nothrow) int(42);
printf("test_p = %p\n", test_p);
delete test_p;
}
When compiling with MSVC, this calls the user-defined `operator new` with either `/MT` or `/MD`.
Unfortunately, libstdc++ doesn't implement this correctly, so it works only with `-static-libstdc++` (the
nothrow overload in libstdc++ DLL invokes the throwing one from the DLL, not the one from the EXE). And
for the same reason it's necessary to overload the sized `operator delete`.
I would like to say v3 is more acceptable than v4 on this aspect. -- Best regards, LIU Hao
OpenPGP_signature.asc
Description: OpenPGP digital signature
_______________________________________________ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
