CODE
class myclass
{
public:
myclass() { тра-та-та }
};
#include <new>
void test()
{
myclass * Tmp = new(nothrow) myclass;
if(!Tmp)
{
cout < "тра-та-та не удалось";
}
}
Но в реальности вижу, что независимо от возвращаемого new(size_t , nothrow_t) значения вызывается конструктор! А ведь new(nothrow) должен вернуть 0, если выделить память не удалось. Он и возвращает, а gcc молча вызывает конструктор с адресом объекта 0. {
public:
myclass() { тра-та-та }
};
#include <new>
void test()
{
myclass * Tmp = new(nothrow) myclass;
if(!Tmp)
{
cout < "тра-та-та не удалось";
}
}
CODE
known_message<decoded_message>* pElement = new(std::nothrow) known_message<decoded_message>(RSSI);
if(pElement)
{
107100: e3a0001c mov r0, #28
107104: e59f1068 ldr r1, [pc, #104]; 107174 <decoder::received(unsigned char)+0x84>
107108: eb00079b bl 108f7c <operator new(unsigned int, std::nothrow_t const&)>
INLINE known_message(uint_fast8_t rssi) : raw_message(T::ID, sizeof(T), rssi) {}
10710c: e1a03007 mov r3, r7
107110: e3a01002 mov r1, #2
107114: e3a02008 mov r2, #8
107118: e1a05000 mov r5, r0
10711c: eb0002ca bl 107c4c <raw_message::raw_message(rf_message::id, unsigned int, unsigned int)>
if(pElement)
{
107100: e3a0001c mov r0, #28
107104: e59f1068 ldr r1, [pc, #104]; 107174 <decoder::received(unsigned char)+0x84>
107108: eb00079b bl 108f7c <operator new(unsigned int, std::nothrow_t const&)>
INLINE known_message(uint_fast8_t rssi) : raw_message(T::ID, sizeof(T), rssi) {}
10710c: e1a03007 mov r3, r7
107110: e3a01002 mov r1, #2
107114: e3a02008 mov r2, #8
107118: e1a05000 mov r5, r0
10711c: eb0002ca bl 107c4c <raw_message::raw_message(rf_message::id, unsigned int, unsigned int)>
Что я упустил? IAR проверял и конструктор не вызывал.
P.S. Код компилируется с -fno-exceptions.