Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang-tidy: IgnoreConversionFromTypes has no effect when set to 'long' #58809

Closed
jarledo opened this issue Nov 4, 2022 · 1 comment · Fixed by #69242
Closed

clang-tidy: IgnoreConversionFromTypes has no effect when set to 'long' #58809

jarledo opened this issue Nov 4, 2022 · 1 comment · Fixed by #69242
Assignees
Labels
clang-tidy confirmed Verified by a second party

Comments

@jarledo
Copy link

jarledo commented Nov 4, 2022

In the following simple example clang-tidy will output a warning when the check cppcoreguidelines-narrowing-conversions is enabled.

int main() {
  long x = 123;
  int y = x;
}
$ clang-tidy --checks='cppcoreguidelines-narrowing-conversions' main.cpp
Error while trying to load a compilation database:
Could not auto-detect compilation database for file "main.cpp"
No compilation database found in /home/user/programming_test or any parent directory
fixed-compilation-database: Error while opening fixed database: No such file or directory
json-compilation-database: Error while opening JSON database: No such file or directory
Running without flags.
2 warnings generated.
/home/user/programming_test/main.cpp:3:7: warning: Value stored to 'y' during its initialization is never read [clang-analyzer-deadcode.DeadStores]
  int y = x;
      ^   ~
/home/user/programming_test/main.cpp:3:7: note: Value stored to 'y' during its initialization is never read
  int y = x;
      ^   ~
/home/user/programming_test/main.cpp:3:11: warning: narrowing conversion from 'long' to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions]
  int y = x;
          ^

This is as expected. However, if I run the same check but with IgnoreConversionFromTypes set to 'long' it still outputs the same warning:

$ clang-tidy --checks='cppcoreguidelines-narrowing-conversions' -config="{CheckOptions: [ {key: cppcoreguidelines-narrowing-conversions.IgnoreConversionFromTypes, value: 'long'} ]}" main.cpp
Error while trying to load a compilation database:
Could not auto-detect compilation database for file "main.cpp"
No compilation database found in /home/user/programming_test or any parent directory
fixed-compilation-database: Error while opening fixed database: No such file or directory
json-compilation-database: Error while opening JSON database: No such file or directory
Running without flags.
2 warnings generated.
/home/user/programming_test/main.cpp:3:7: warning: Value stored to 'y' during its initialization is never read [clang-analyzer-deadcode.DeadStores]
  int y = x;
      ^   ~
/home/user/programming_test/main.cpp:3:7: note: Value stored to 'y' during its initialization is never read
  int y = x;
      ^   ~
/home/user/programming_test/main.cpp:3:11: warning: narrowing conversion from 'long' to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions]
  int y = x;
          ^

It seems to only happen with the type long, if I run the same example but replace long x = 123; with size_t x = 123; then it works to set IgnoreConversionFromTypes to 'size_t'.

This is running Ubuntu 22.04 with clang-tidy installed with apt install:

$ clang-tidy --version
Ubuntu LLVM version 14.0.0

  Optimized build.
  Default target: x86_64-pc-linux-gnu
  Host CPU: skylake
@jarledo jarledo changed the title IgnoreConversionFromTypes has no effect when set to 'long' clang-tidy: IgnoreConversionFromTypes has no effect when set to 'long' Nov 4, 2022
@llvmbot
Copy link
Collaborator

llvmbot commented Nov 4, 2022

@llvm/issue-subscribers-clang-tidy

@PiotrZSL PiotrZSL added the confirmed Verified by a second party label Oct 16, 2023
@PiotrZSL PiotrZSL self-assigned this Oct 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment