llvm / llvm-project

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

`clang-tidy`: `clang-tidy` incorrectly treats a global function as a global variable [readability-identifier-naming] #99053

Open GTruf opened 1 month ago

GTruf commented 1 month ago

clang-tidy version:

$ clang-tidy --version
LLVM (http://llvm.org/):
  LLVM version 18.1.1
  Optimized build.

There is the following .clang-tidy configuration file:

---
Checks: '-*, readability-identifier-naming'
CheckOptions:
- { key: readability-identifier-naming.GlobalFunctionCase, value: lower_case }
- { key: readability-identifier-naming.GlobalVariableCase, value: lower_case }
- { key: readability-identifier-naming.GlobalVariablePrefix, value: g_ }

There is the following code:

void fill_resources_from_uri(std::vector<int>& resources)
{
}

If I change vector to stack, everything is fine, but if I leave vector or list, clang-tidy displays the following error:

$ clang-tidy AdapterTest.cpp -p out/Release/

AdapterTest.cpp:30:6: warning: invalid case style for global variable 'fill_resources_from_uri' [readability-identifier-naming]
   30 | void fill_resources_from_uri(std::vector<int>& resources)
      |      ^~~~~~~~~~~~~~~~~~~~~~~
      |      g_fill_resources_from_uri

But clang-tidy also generates the following error (maybe the code analyzer breaks because of it):

.../include/c++/13.1.0/cstddef:50:10: error: 'stddef.h' file not found [clang-diagnostic-error]
   50 | #include <stddef.h>
      |          ^~~~~~~~~~ 

The build configuration is under GCC 13.1.

PiotrZSL commented 1 month ago

Yes, AST is constructed incorrectly due to missing include, and that's why this false-positive