Skip to content

clang-tidy misc-include-cleaner does not detect chrono header #98122

Open
@andrea-cassioli-maersk

Description

@andrea-cassioli-maersk

I have noticed that when running with misc-include-cleaner option, clang-tidy seems not to detect that the chrono header is provided and used.

In one of my project file you can find

#include <algorithm>
#include <chrono>
#include <functional>
#include <set>
#include <string>

// some other code

 const auto time_residual = rotation_time - std::chrono::round<std::chrono::weeks>(t);
  constexpr std::chrono::minutes kThreshold{30};
  if (std::chrono::abs(time_residual) > kThreshold) {
    results << ErrorMessage("FOO");
  }

// and more code goes here

Running clang-tidy I get

/Users/<my-path>/foo.cpp:241:68: error: no header providing "std::chrono::round" is directly included [misc-include-cleaner,-warnings-as-errors]
    2 |   const auto time_residual = rotation_time - std::chrono::round<std::chrono::weeks>(t);
      |   

and the header #include <__chrono/duration.h> is added to the file.

Notice it is not only std::chrono::round that is not found, but std::chrono::weeks as well.

I am running on

➜  $ clang-tidy --version
Homebrew LLVM version 18.1.8
  Optimized build.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions