LINUX.ORG.RU

История изменений

Исправление dissident, (текущая версия) :

Т.е. имея external_library и external_library.h, но не имея external_library.cpp (например оно в so):

external_library.h

struct A {
   // see above
};
void sink(A&&); // defined in external_library.cpp not available

Вот этот код UB:

#include <external_library.h>
...
A *a = new A();
sink(*a);
delete a; // UB: can crash if sink moves A to smth (takes ownership)

И вот этот код potential memory leak:

#include <external_library.h>
...
A *a = new A();
sink(*a);
// leaks if sink does not move A to smth (does not take ownership)

Правильно я понял?

Или таки существует где-то гарантия, что move constructor должен оставить передаваемый объект в destructible state?

Меня последний вопрос интересует.

Исправление dissident, :

Т.е. имея external_library и external_library.h, но не имея external_library.cpp (например оно в so):

external_library.h

struct A {
   // see above
};
void sink(A&&); // defined in external_library.cpp not available

Вот этот код UB:

#include <external_library.h>
...
A *a = new A();
sink(*a);
delete a; // UB: can crash if sink moves A to smth (takes ownership)

И вот этот код potential memory leak:

#include <external_library.h>
...
A *a = new A();
sink(*a);
// if sink does not move A to smth (does not take ownership)

Правильно я понял?

Или таки существует где-то гарантия, что move constructor должен оставить передаваемый объект в destructible state?

Меня последний вопрос интересует.

Исправление dissident, :

Т.е. имея external_library и external_library.h, но не имея external_library.cpp (например оно в so):

external_library.h

struct A {
   // see above
};
void sink(A&&); // defined in external_library.cpp not available

Вот этот код UB:

#include <external_library.h>
...
A *a = new A();
sink(*a);
delete a; // UB: can crash if sink moves A to smth (takes ownership)

И вот этот код potential memory leak:

#include <external_library.h>
...
A *a = new A();
sink(*a);
// if sink does not move A to smth (does not take ownership)

Правильно я понял?

Или таки существует где-то гарантия, что move constructor должен оставить передаваемый объект в destructable state?

Меня последний вопрос интересует.

Исходная версия dissident, :

Т.е. имея external_library и external_library.h, но не имея external_library.cpp (например оно в so):

external_library.h

struct A {
   // see above
};
void sink(A&&); // defined in external_library.cpp not available

Вот этот код UB:

#include <external_library.h>
...
A *a = new A();
sink(*a);
delete a; // UB: can crash if sink moves A to smth (takes ownership)

И вот этот код potential memory leak:

#include <external_library.h>
...
A *a = new A();
sink(*a);
// if sink does not moves A to smth (does not take ownership)

Правильно я понял?

Или таки существует где-то гарантия, что move constructor должен оставить передаваемый объект в destructable state?

Меня последний вопрос интересует.