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

Dealing with defines #56

Open
bchretien opened this issue Aug 29, 2014 · 2 comments
Open

Dealing with defines #56

bchretien opened this issue Aug 29, 2014 · 2 comments

Comments

@bchretien
Copy link
Collaborator

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.

@myint
Copy link
Owner

myint commented Aug 30, 2014

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.

christarazi added a commit to christarazi/cppclean that referenced this issue Sep 18, 2017
This change modifies WarningHunter._determine_uses()._add_use() to take
in a full VariableDeclaration object instead of Type. This allows us to
check for the initial_value attribute of a VariableDeclaration object
which may contain a symbol from an included file (e.g. a #define). This
change also exports Define objects in order to capture their value and
check if they are being used.

To fully implement the issue rasied in myint#56, inline constructor member
initializer lists need to be supported.
@drodil
Copy link

drodil commented Feb 20, 2018

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");
}

myint pushed a commit that referenced this issue Mar 31, 2018
…nes with values (#128)

* Implement preliminary solution to #56 for exporting defines

This change modifies WarningHunter._determine_uses()._add_use() to take
in a full VariableDeclaration object instead of Type. This allows us to
check for the initial_value attribute of a VariableDeclaration object
which may contain a symbol from an included file (e.g. a #define). This
change also exports Define objects in order to capture their value and
check if they are being used.

To fully implement the issue rasied in #56, inline constructor member
initializer lists need to be supported.

* Implement basic support for ctor initializer lists

This change adds basic support for initializing variables (initial_value
attribute of VariableDeclaration) inside ctor initializer lists. It only
supports one parameter for a given member. The ctor must also be inline
defined. In other words, a ctor with its definition outside the class is
not supported. Below is an example of what's supported:

```
class Foo
{
public:
  Foo() :
    foo(1)
  {}

private:
  int foo;
};
```

In this case, the `initial_value` of `foo` is set to `1`.

Whereas, the following is not supported, and will be ignored:

```
class Foo
{
public:
  Foo() :
    bar(1, 2, 3, 4)
  {}

private:
  Bar bar;
};
```

This ctor is defined outside the class, and thus not supported:

```
class Foo
{
public:
  Foo();

private:
  Bar bar;
};

Foo:Foo() :
  bar(1)
{}
```

* Add tests for ctor initializer lists

* Fix travis ci errors

* Fix using explicit python3 type

This fixes the broken build for Python 2.

* Fix inconsistency with usage of local variable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants