Skip to content

clangd suggests I delete the required <ranges> include #64191

Closed
@FalcoGer

Description

@FalcoGer

Clang version is

Ubuntu clang version 17.0.0 (++20230724042330+c48ed93cf8c9-1~exp1~20230724042441.1077)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

The following example produces the bug. It compiles fine with clang++ -std=c++23 test.cpp -o test

#include <iostream>
#include <ranges>
int main()
{
    const int MAGIC {5};
    for (auto i : std::ranges::views::iota(0) | std::ranges::views::take(MAGIC))
    {
        std::cout << i << '\n';
    }
    return 0;
}

clangd however produces this diagnostic for line 2 (#include <ranges>)

Included header ranges is not used directly (fix available) (clangd unused-includes)
──────────────────────────────────────────────────────────────────────────────
https://clangd.llvm.org/guides/include-cleaner

The suggested "fix" is to delete the line, which causes the program to not compile anymore.

Since is a standard library feature, I don't think any of the solutions outlined in the provided link are particularly doable, like adding // IWYU comments to the ranges header file. A workaround would be to include an exception for the ranges header in the configuration file, but trying to add that, I get this error:

Property MissingIncludes is not allowed. (yaml-schema: diagnostics)
Property Includes is not allowed. (yaml-schema: diagnostics)

for this configuration

Diagnostics:
  UnusedIncludes: Strict
  MissingIncludes: Strict
  Includes:
    IgnoreHeader: ranges\.h
  ClangTidy:
    Add: [
      # ...
    ]
    Remove: [
      # ...
    ]
    CheckOptions:
      # ...

And adding // IWYU pragma: keep doesn't work either.

image

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