Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cpp clean tells me I need to #include something that I can forward declare. #60

Open
ChopsII opened this issue Mar 20, 2015 · 5 comments

Comments

@ChopsII
Copy link

ChopsII commented Mar 20, 2015

Consider the following:

class Blah;
class Foo: public Bar{
public:
    Foo();
    virtual bool doSomething(Blah* blah);
};

Cppclean thinks that I need to #include "blah.h" even though I'm only using it in pointer form:
"Foo.h:1: 'Blah' forward declared, but needs to be #included"

The code compiles fine with the forward declare.

@myint
Copy link
Owner

myint commented Mar 20, 2015

I can't reproduce this:

$ cat Foo.h
class Blah;
class Foo: public Bar{
public:
    Foo();
    virtual bool doSomething(Blah* blah);
};
$ ./cppclean Foo.h

@ChopsII
Copy link
Author

ChopsII commented Mar 23, 2015

My examples wasn't good. I'll need to look further into this to work out what's going on, but may not have time. My project is very large so it could be very difficult to reduce it to a Minimal, Complete, and Verifiable example
Is there a chance that cppclean could give the reason behind its conclusions? Like, it says something needs to be #included, can it give the location of the code that requires the #include, as well as the location of the forward-declare that it gives now?

@nmoreaud
Copy link

I've got this kind of behaviour in specific templates.
Ex :

class Data;

class Toto {
QPointer<Data> _socket
}

QPointer stores a pointer, it doesn't need access to Data implementation.
This is the same for many smart pointers classes.

@Chaosmeister
Copy link

Would something that was forward declared but needs to be included even compile?

@romintomasetti
Copy link

The following might help.

This works:

class MyCoolClass;

int do_something(MyCoolClass * ptr);

but this raises 'MyCoolClass' forward declared, but needs to be #included:

class MyCoolClass;

template <typename T>
T do_something(MyCoolClass * ptr)
{
    // whatever
    return 0;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants