cppclean
cppclean copied to clipboard
Incomplete type, std::shared_ptr, and alias declaration
cppclean seems to be clever enough to determine that you can have a std::shared_ptr<X> to a forward-declared type X, which is good.
Unfortunately, if the name is hidden behind an alias declaration, cppclean then warns that X must be #included. The following test code demonstrates the issue:
#include <memory>
// Forward declaration of class X is all that is required to have a std::shared_ptr
class X;
// Alias declaration - requires C++11
template<typename T>
using MySharedPtr = std::shared_ptr<T>;
struct A
{
MySharedPtr<X> x;
};
For this case, cppclean prints:
cppclean_test5.h:4: 'X' forward declared, but needs to be #included
On the other hand, if you change the line MySharedPtr<X> x; to simply std::shared_ptr<X> x;, the warning goes away. So I guess this is really more of a feature request to better handle alias declarations, as we use this technique to handle backwards compatibility with older compilers in our library.