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 header would be enough #122847

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 cstddef because of constructor (or may be method) implementation when it its inclusion in header should be enough.

clang-tidy misc-include-cleaner output:

clang-tidy -checks="-*,misc-include-cleaner" Method.cpp 
1 warning generated.
Method.cpp:3:18: warning: no header providing "size_t" is directly included [misc-include-cleaner]
    2 | 
    3 | Test::Test(const size_t size)
      |                  ^

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

Header file (Method.h):

#pragma once

#include <cstddef>

class Test
{
public:
    Test(const size_t size);

protected:
    size_t size_;
};

Source file (Method.cpp):

#include "Method.h"

Test::Test(const size_t size)
:   size_(size)
{
}
@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 `cstddef` because of constructor (or may be method) implementation when it its inclusion in header should be enough.

clang-tidy misc-include-cleaner output:

clang-tidy -checks="-*,misc-include-cleaner" Method.cpp 
1 warning generated.
Method.cpp:3:18: warning: no header providing "size_t" is directly included [misc-include-cleaner]
    2 | 
    3 | Test::Test(const size_t size)
      |                  ^

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

Header file (Method.h):

#pragma once

#include &lt;cstddef&gt;

class Test
{
public:
    Test(const size_t size);

protected:
    size_t size_;
};

Source file (Method.cpp):

#include "Method.h"

Test::Test(const size_t size)
:   size_(size)
{
}

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