I have 3 files
test.h
#pragma once
#include <memory>
std::unique_ptr<int> createInt();
test.cpp - pay attention test.h wasn't included
#include <memory>
std::shared_ptr<int> createInt()
{
return std::make_shared<int>();
}
main.cpp
#include "test.h"
int main()
{
createInt();
return 0;
}
It compiles with out any problems with
g++ -Wall -Wextra main.cpp test.cpp
And fails in runtime:
./a.out
a.out(3632,0x7fff78ba9300) malloc: *** error for object 0x7fe290404c68: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Abort trap: 6
However Visual studio doesn't compile such source with LNK1120 error.
Why g++ linker doesn't fail such code?