clangd
clangd copied to clipboard
unused-includes: Problem with forward declared types
When a type is forward declared in a header, and declared in another, clangd marks the declaration's header unused, even if it is required. This is a minimal code I could reproduce the error with:
main.c
#include "decl.h" /* Included header decl.h is not used directly (fix available) clangd(unused-includes) */
#include <stdio.h>
void print_container(container_t* container)
{
printf("%d\n", container->data); /* decl.h is needed because of this member access, fwd.h is not enough */
}
int main() {
container_t container = {5};
print_container(&container);
return 0;
}
fwd.h
#ifndef FWD_H
#define FWD_H
typedef struct container_t container_t;
#endif
decl.h
#ifndef DECL_H
#define DECL_H
#include "fwd.h"
struct container_t {
int data;
};
#endif
System information
Output of clangd --version:
clangd version 17.0.3 (https://github.com/llvm/llvm-project 888437e1b60011b8a375dd30928ec925b448da57)
Features: linux+grpc
Platform: x86_64-unknown-linux-gnu
Editor/LSP plugin:
llvm-vs-code-extensions.vscode-clangd
v0.1.25
Operating system:
x86_64 GNU/Linux