Skip to content

[clang-tidy] misc-include-cleaner false positive for <net/if.h> header #97033

Open
@abdelmaged

Description

@abdelmaged

clang-tidy version:

LLVM (http://llvm.org/):
  LLVM version 18.1.6
  Optimized build.

Consider following C file main.c

#include <net/if.h>
#include <stdio.h>

int main(int argc, char **argv) {
  printf("%d\n", IFF_LOOPBACK);
  return 0;
}

Running check misc-include-cleaner like in command:

clang-tidy --checks=misc-include-cleaner main.c --

Results in the following false warning:

1 warning generated.
main.c:1:1: warning: included header if.h is not used directly [misc-include-cleaner]
    1 | #include <net/if.h>
      | ^~~~~~~~~~~~~~~~~~~
    2 | #include <stdio.h>

When applying suggestion then recompile using clang main.c, we will get following compilation error:

main.c:5:18: error: use of undeclared identifier 'IFF_LOOPBACK'
    5 |   printf("%d\n", IFF_LOOPBACK);
      |                  ^
1 error generated.

net/if.h is from glibc library, and we may see its contents in:
https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/gnu/net/if.h;hb=e84eabb3871c9b39e59323bf3f6b98c2ca9d1cd0

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