smart pointer incomplete type

//file: a.h
1
2
3
4
5
6
7
8
#pragma once
#include <iostream>

struct A {
	~A() {
		std::cout << "~A" << std::endl;
	}
};

//file: b.h
1
2
3
4
5
6
7
8
9
#pragma once
#include <memory>

class A;
struct B {
	B();
	//A is incomplete type
	std::shared_ptr<A> pa_;
};

//b.cpp
1
2
3
4
5
6
#include "b.h"
#include "a.h"

B::B():pa_{ new A{} }
{
}

//main.cpp:main function
1
2
3
4
5
6
7
#include "b.h"

int main() {
	{
		B b;
	}
}


I think that "~A" will not be outputed, because class A is an incomplete type in B's destructor.
But gcc 6.2 and vs2015 both output "~A".
Topic archived. No new replies allowed.