llvm / llvm-project

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

[clang] Clang does not diagnose unused private member functions #106678

Open carlosgalvezp opened 1 month ago

carlosgalvezp commented 1 month ago

Hi!

I notice clang doesn't diagnose this unused private member function:

class Foo
{
 private:
    void foo(){}
};

https://godbolt.org/z/nPTPd4dqc

I'm curious to understand why that's the case. Is there high likelihood of false positives?

Thanks!

llvmbot commented 1 month ago

@llvm/issue-subscribers-clang-frontend

Author: Carlos Galvez (carlosgalvezp)

Hi! I notice clang doesn't diagnose this unused private member function: ```cpp class Foo { private: void foo(){} }; ``` https://godbolt.org/z/nPTPd4dqc I'm curious to understand why that's the case. Is there high likelihood of false positives? Thanks!
AaronBallman commented 1 month ago

We diagnose unused private fields which suggests we really should handle unused private functions (and other private declarations as well). I can't think of a reason not to warn on them.