llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.87k stars 11.93k forks source link

clang-tidy: misc-include-cleaner: C++ headers are inserted into C code #113926

Open JanMatCodasip opened 1 week ago

JanMatCodasip commented 1 week ago

Clang-tidy (check misc-include-cleaner) inserts C++ headers into plain C code. For example #include <cinttypes> instead of the expected #include <inttypes.h>.

Steps to reproduce:

# Extract the attached archive
tar xvf test-includes.tar.gz
cd test-includes

# Build the example program (compilation database is also created in the process)
mkdir build && cd build
cmake ..
cmake --build .

run-clang-tidy-18.py -header-filter='-*' -checks='-*,misc-include-cleaner' -fix

# Observe that main.c now contains "#include <cinttypes>" as opposed to "#include <inttypes.h>".

Thank you.

test-includes.tar.gz

llvmbot commented 1 week ago

@llvm/issue-subscribers-clang-include-cleaner

Author: Jan Matyas (JanMatCodasip)

Clang-tidy (check `misc-include-cleaner`) inserts C++ headers into plain C code. For example `#include <cinttypes>` instead of the expected `#include <inttypes.h>`. Steps to reproduce: ```bash # Extract the attached archive tar xvf test-includes.tar.gz cd test-includes # Build the example program (compilation database is also created in the process) mkdir build && cd build cmake .. cmake --build . run-clang-tidy-18.py -header-filter='-*' -checks='-*,misc-include-cleaner' -fix # Observe that main.c now contains "#include <cinttypes>" as opposed to "#include <inttypes.h>". ``` Thank you. [test-includes.tar.gz](https://github.com/user-attachments/files/17544742/test-includes.tar.gz)