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

[clang-include-cleaner] suggest to insert header in source file when headers with base/derived class would be enough #122850

Open
EugeneZelenko opened this issue Jan 14, 2025 · 1 comment
Labels
clang-include-cleaner false-positive Warning fires when it should not

Comments

@EugeneZelenko
Copy link
Contributor

clang-include-cleaner suggest to include header with forward declaration when headers with base/derived classes should be enough.

clang-tidy misc-include-cleaner output:

clang-tidy -checks="-*,misc-include-cleaner" Forward.cpp 
4 warnings generated.
Forward.cpp:3:39: warning: no header providing "detail::Forward" is directly included [misc-include-cleaner]
    2 | 
    3 | void Test::do_something(const detail::Forward& /*forward*/)
      |                                       ^

I tried clang-include-cleaner from main (7d8b4eb).

Base class header file (Base.h):

#pragma once

namespace detail
{
    class Forward;
}

class Base
{
public:
    virtual void do_something(const detail::Forward& forward);
};

Header file (Forward.h):

#pragma once

#include "Base.h"

class Test : public Base
{
public:
    void do_something(const detail::Forward& forward) override;
};

Source file (Forward.cpp):

#include "Forward.h"

void Test::do_something(const detail::Forward& /*forward*/)
{
}
@EugeneZelenko EugeneZelenko added clang-include-cleaner false-positive Warning fires when it should not labels Jan 14, 2025
@llvmbot
Copy link
Member

llvmbot commented Jan 14, 2025

@llvm/issue-subscribers-clang-include-cleaner

Author: None (EugeneZelenko)

`clang-include-cleaner` suggest to include header with forward declaration when headers with base/derived classes should be enough.

clang-tidy misc-include-cleaner output:

clang-tidy -checks="-*,misc-include-cleaner" Forward.cpp 
4 warnings generated.
Forward.cpp:3:39: warning: no header providing "detail::Forward" is directly included [misc-include-cleaner]
    2 | 
    3 | void Test::do_something(const detail::Forward& /*forward*/)
      |                                       ^

I tried clang-include-cleaner from main (7d8b4eb).

Base class header file (Base.h):

#pragma once

namespace detail
{
    class Forward;
}

class Base
{
public:
    virtual void do_something(const detail::Forward& forward);
};

Header file (Forward.h):

#pragma once

#include "Base.h"

class Test : public Base
{
public:
    void do_something(const detail::Forward& forward) override;
};

Source file (Forward.cpp):

#include "Forward.h"

void Test::do_something(const detail::Forward& /*forward*/)
{
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang-include-cleaner false-positive Warning fires when it should not
Projects
None yet
Development

No branches or pull requests

2 participants