LukasScheucher / include-what-you-use

Automatically exported from code.google.com/p/include-what-you-use
Other
0 stars 0 forks source link

Forward declarations and shared_ptr #186

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
The problem arises when class B has a method with shared_ptr<A> as an argument. 
IWYU suggests removing #include "A.h" from B.cpp:

B.cpp should remove these lines:
- #include "A.h"  // lines 1-1

 which causes "member access into incomplete type" error upon compilation.

Source files are listed below:

A.h:
#pragma once 

class A {
public:
    int x;
};

B.h:
#pragma once

#include <memory>
class A;

class B {
public:
    B();
    void f(std::shared_ptr<A> aPtr);
};

B.cpp:
#include "A.h"
#include "B.h"
#include <iostream>

B::B() {
    std::cout << "B" << std::endl;
}

void B::f(std::shared_ptr<A> aPtr) {
    std::cout << aPtr->x;
}

I tried replacing std::shared_ptr with some sample template class and it works 
fine, the include suggestions are correct.

Original issue reported on code.google.com by victor.a...@gmail.com on 28 Apr 2015 at 9:09