Skip to content

clang-tidy: bugprone-multi-level-implicit-pointer-conversion it too noisy for void* conversions #93959

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

Closed
t-b opened this issue May 31, 2024 · 2 comments · Fixed by #94524
Closed
Assignees
Labels
clang-tidy confirmed Verified by a second party

Comments

@t-b
Copy link

t-b commented May 31, 2024

Version:

Debian clang version 18.1.6 (++20240518023133+1118c2e05e67-1~exp1~20240518143227.130)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

CMakeLists.txt

cmake_minimum_required(VERSION 3.10)

project(test CXX)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

add_executable(test test.cpp)

test.cpp

#include <cstdlib>

int main(int argc, char** argv)
{
  char** p = nullptr;
  free(p);

  free((void*) p);

  free(static_cast<void*>(p));
}

Recipe:

cmake -B build -S .
run-clang-tidy-18 -p build -checks="-*,bugprone-multi-level-implicit-pointer-conversion"

Output:

Enabled checks:
    bugprone-multi-level-implicit-pointer-conversion

clang-tidy-18 -checks=-*,bugprone-multi-level-implicit-pointer-conversion -p=build /home/firma/devel/test/test.cpp
/home/firma/devel/test/test.cpp:6:8: warning: multilevel pointer conversion from 'char **' to 'void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion]
    6 |   free(p);
      |        ^
/home/firma/devel/test/test.cpp:8:16: warning: multilevel pointer conversion from 'char **' to 'void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion]
    8 |   free((void*) p);
      |                ^
/home/firma/devel/test/test.cpp:10:27: warning: multilevel pointer conversion from 'char **' to 'void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion]
   10 |   free(static_cast<void*>(p));
      |                           ^
3 warnings generated.

I don't understand why I get the warning here, in addition the suggested ways to "improve" the code using a cast don't work.

@PiotrZSL
Copy link
Member

This is problem with check.
In your example you not removing implicit conversion, you just adding additional explicit one with void*.

In code like this:

#include <cstdlib>

int main(int argc, char** argv)
{
  char** p = nullptr;
  free(p);

  free((char*) p);

  free(reinterpret_cast<char*>(p));
}

issue isn't show up. Anyway check need to be relaxed to allow any explicit cast (to void* also).
You can always also use NOLINT as temporary solution

@PiotrZSL PiotrZSL added the confirmed Verified by a second party label May 31, 2024
@PiotrZSL PiotrZSL self-assigned this Jun 5, 2024
PiotrZSL added a commit to PiotrZSL/llvm-project that referenced this issue Jun 5, 2024
Ignore implicit pointer conversions that are part of a cast expression

Closes llvm#93959
nekoshirro pushed a commit to nekoshirro/Alchemist-LLVM that referenced this issue Jun 9, 2024
…llvm#94524)

Ignore implicit pointer conversions that are part of a cast expression

Closes llvm#93959

Signed-off-by: Hafidz Muzakky <[email protected]>
@t-b
Copy link
Author

t-b commented Jun 10, 2024

@PiotrZSL Thanks for the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang-tidy confirmed Verified by a second party
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants