Skip to content

[clang-tidy] misc-include-cleaner suggests the wrong header for std::ranges::upper_bound #94459

Closed
@yalavrinenko

Description

@yalavrinenko

For the following example

#include <algorithm>

struct Foo {
  int value;
  double bar() const { return value * 2; }
};

int main() {
  std::vector<Foo> v;
  const double to_find = 10;
  std::ranges::upper_bound(v, to_find, std::less{}, &Foo::bar);

  return 0;
}

misc-include-cleaner emits errors

*/sandbox.cpp:57:16: error: no header providing "std::ranges::binary_search" is directly included [misc-include-cleaner,-warnings-as-errors]
   33 |   std::ranges::binary_search(v, to_find, std::less{}, &Foo::bar);

as well as

sandbox.cpp:35:1: error: included header algorithm is not used directly [misc-include-cleaner,-warnings-as-errors]

The suggested fix is #include <bits/ranges_algo.h> that seems incorrect.

The same function std::ranges::sort from this header (<bits/ranges_algo.h>) is handled perfectly.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions