cppclean icon indicating copy to clipboard operation
cppclean copied to clipboard

Dealing with defines

Open bchretien opened this issue 9 years ago • 2 comments

If one includes a header where a macro is defined, cppclean will not be able to detect that the header can actually be needed. This may be clearer with the following dummy example.

Example:

foo.h

#ifndef FOO_H
# define FOO_H

# include "bar.h"

class Foo
{
public:
  Foo () : bar (BAR) {}

private:
  int bar;
};

#endif //! FOO_H

bar.h

#ifndef BAR_H
# define BAR_H

# define BAR 1

#endif //! BAR_H

Running cppclean gives:

$ cppclean --verbose .
Processing ./bar.h
Processing ./foo.h
./foo.h:4: 'bar.h' does not need to be #included

This may be something to add to the "planned" features, unless this requires some analysis that this tool is not meant to achieve. If that's the case, this may be worth noting somewhere in the documentation/help message.

bchretien avatar Aug 29 '14 13:08 bchretien

Thanks for reporting this. I don't have time to look at this in the near term, but, I've added you as a collaborator to this repository.

myint avatar Aug 30 '14 00:08 myint

Hi,

The same goes if you have for example:

string.h

using MyString = std::string;

main.cpp

#include "string.h"

void run() {
    MyString hello("Hello world");
}

drodil avatar Feb 20 '18 06:02 drodil