llvm / llvm-project

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

misc-include-cleaner breaks code #104585

Open ben-freist opened 3 months ago

ben-freist commented 3 months ago

I hope this is the right channel, I'm getting incorrect behaviour from clang-tidy on code that uses ICU.

I'm using ubuntu 22.04, I've tried clang-tidy-17, clang-tidy-18 and I built one myself based on (22bc9db92b46965882b1c77aebc86430149b0912), the results are the same for all three.

CMakeLists.txt:

cmake_minimum_required(VERSION 3.12)

project(tidy_bug)

find_package(ICU 50 COMPONENTS uc REQUIRED)
add_library(my_lib file.cpp)
target_link_libraries(my_lib ICU::uc)

file.cpp

#include <utility>
#include <unicode/uchar.h>
#include <string_view>

bool function(std::string_view input)
{
    size_t res = 0;
    char const * const s = input.data();
    auto const length = static_cast<int32_t>(input.size());
    int32_t pos = 0;
    UChar32 c;
    U8_NEXT(s, pos, length, c);
    return u_isWhitespace(c);
}

I'm using ICU version 70.1.

I'm building the project like this: cmake -DCMAKE_CXX_COMPILER=clang++-18 -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_CXX_STANDARD=20 ..

And I'm applying clang-tidy like this: clang-tidy -p build/ --config='{"Checks": "misc-include-cleaner"}' --fix file.cpp.

The result has the includes unicode/umachine.h, unicode/utf8.h and unicode/urename.h none of which contain u_isWhitespace.

llvmbot commented 3 months ago

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

Author: None (ben-freist)

I hope this is the right channel, I'm getting incorrect behaviour from clang-tidy on code that uses ICU. I'm using ubuntu 22.04, I've tried clang-tidy-17, clang-tidy-18 and I built one myself based on (22bc9db92b46965882b1c77aebc86430149b0912), the results are the same for all three. CMakeLists.txt: ``` cmake_minimum_required(VERSION 3.12) project(tidy_bug) find_package(ICU 50 COMPONENTS uc REQUIRED) add_library(my_lib file.cpp) target_link_libraries(my_lib ICU::uc) ``` file.cpp ``` #include <utility> #include <unicode/uchar.h> #include <string_view> bool function(std::string_view input) { size_t res = 0; char const * const s = input.data(); auto const length = static_cast<int32_t>(input.size()); int32_t pos = 0; UChar32 c; U8_NEXT(s, pos, length, c); return u_isWhitespace(c); } ``` I'm using ICU version 70.1. I'm building the project like this: `cmake -DCMAKE_CXX_COMPILER=clang++-18 -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_CXX_STANDARD=20 ..` And I'm applying clang-tidy like this: `clang-tidy -p build/ --config='{"Checks": "misc-include-cleaner"}' --fix file.cpp`. The result has the includes `unicode/umachine.h`, `unicode/utf8.h` and `unicode/urename.h` none of which contain `u_isWhitespace`.