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 false positive when ADL finds a function at 2nd phase of two-phase name lookup #116517

Open geza-herman opened 3 hours ago

geza-herman commented 3 hours ago

For this 4-file setup, clang-tidy reports that bar.hpp is unused in main.cpp. But this is incorrect, it is necessary for the example to compile.

// main.cpp
#include "call_bar.hpp"
#include "bar.hpp"
#include "base.hpp"

int main() {
    return call_bar(Base());
}
// call_bar.hpp
#ifndef CALL_BAR_HPP
#define CALL_BAR_HPP

template <typename T>
int call_bar(T t) {
    return bar(t);
}

#endif
// bar.hpp
#ifndef BAR_HPP
#define BAR_HPP

#include "base.hpp"

int bar(Base) {
    return 0;
}

#endif
// base.hpp
#ifndef BASE_HPP
#define BASE_HPP

struct Base {};

#endif
llvmbot commented 3 hours ago

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

Author: None (geza-herman)

For this 4-file setup, clang-tidy reports that `bar.hpp` is unused in `main.cpp`. But this is incorrect, it is necessary for the example to compile. ```c++ // main.cpp #include "call_bar.hpp" #include "bar.hpp" #include "base.hpp" int main() { return call_bar(Base()); } ``` ```c++ // call_bar.hpp #ifndef CALL_BAR_HPP #define CALL_BAR_HPP template <typename T> int call_bar(T t) { return bar(t); } #endif ``` ```c++ // bar.hpp #ifndef BAR_HPP #define BAR_HPP #include "base.hpp" int bar(Base) { return 0; } #endif ``` ```c++ // base.hpp #ifndef BASE_HPP #define BASE_HPP struct Base {}; #endif ```