llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[clang-tidy] `misc-const-correctness` false positive

Open davidmenggx opened this issue 3 months ago • 1 comments

The following suggestion does not compile:

void func(int* p) {
    int* r = p;
    int* v = p;
    *(r = v) = 0;
}
<source>:2:5: warning: pointee of variable 'r' of type 'int *' can be declared 'const' [misc-const-correctness]
    2 |     int* r = p;
      |     ^  
      |         const

Godbolt (trunk): https://godbolt.org/z/3o8qnEKs3

davidmenggx avatar Aug 13 '26 13:08 davidmenggx

@llvm/issue-subscribers-clang-tidy

Author: David Meng (davidmenggx)

The following suggestion does not compile: ```cpp void func(int* p) { int* r = p; int* v = p; *(r = v) = 0; } ``` ``` <source>:2:5: warning: pointee of variable 'r' of type 'int *' can be declared 'const' [misc-const-correctness] 2 | int* r = p; | ^ | const ``` Godbolt (trunk): https://godbolt.org/z/3o8qnEKs3