llvm / llvm-project

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

readability-identifier-naming does not correctly identify the scope for variables and constants #41979

Open llvmbot opened 5 years ago

llvmbot commented 5 years ago
Bugzilla Link 42634
Version unspecified
OS Windows NT
Reporter LLVM Bugzilla Contributor

Extended Description

using LLVM (http://llvm.org/): LLVM version 8.0.0 Optimized build. Default target: x86_64-pc-linux-gnu Host CPU: skylake

given a .c file with only the following content:

static uint32 const someUnitInternalConst = 4; static uint8 someUnitSimpleList[] = {1, 2, 3};

and the following configuration:

- { key:  readability-identifier-naming.StaticConstantCase,                   value:  camelBack       }
- { key:  readability-identifier-naming.ConstantCase,                         value:  camelBack       }
- { key:  readability-identifier-naming.LocalConstantCase,                    value:  camelBack       }
- { key:  readability-identifier-naming.GlobalConstantCase,                   value:  CamelCase       }

- { key:  readability-identifier-naming.LocalVariableCase,                    value:  camelBack       }
- { key:  readability-identifier-naming.LocalPointerCase,                     value:  camelBack       }
- { key:  readability-identifier-naming.LocalConstantPointerCase,             value:  camelBack       }
- { key:  readability-identifier-naming.StaticVariableCase,                   value:  camelBack       }
- { key:  readability-identifier-naming.GlobalVariableCase,                   value:  CamelCase       }

clang-tidy still throws the following errors (using [readability-identifier-naming,-warnings-as-errors])

error: invalid case style for global constant 'someUnitInternalConst' [readability-identifier-naming,-warnings-as-errors] static uint32 const someUnitInternalConst = 4; ^~~~~ SomeUnitInternalConst

error: invalid case style for global variable 'someUnitSimpleList' [readability-identifier-naming,-warnings-as-errors] static uint8 someUnitSimpleList[] = {1, 2, 3}; ^~~~~~ SomeUnitSimpleList

thus clang-tidy interprets the static (local) variables as global variables - which is wrong (?)

Rory101 commented 2 years ago

Have there been any updates on this? I'm having the exact same problem using the clangd extension for vscode. The version of the vscode clangd extension is: v0.1.15 I think the actual version of clangd that is used is: v14.0.3

PiotrZSL commented 1 year ago

No bug here, this someUnitInternalConst here is a GlobalConstantCase, StaticConstantCase is for static const variables in functions only.

spoorcc commented 1 year ago

Does this mean that clang cannot differentiate between translation unit scope (static uint8 someUnitSimpleList[] = {1, 2, 3};) and global scope (uint8 someUnitSimpleGLobalList[] = {1, 2, 3};) in C?

PiotrZSL commented 1 year ago

It looks like that, they both global variables, with different linkage but global.

spoorcc commented 1 year ago

ok thanks for the answer, to bad