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

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

Open electricbrass opened this issue 3 months ago • 4 comments

void func(int* ptr1)
{
    int* ptr2 = ptr1;
    *ptr2++ = 0;
}
warning: pointee of variable 'ptr2' of type 'int *' can be declared 'const' [misc-const-correctness]
    3 |     int* ptr2 = ptr1;
      |     ^  
      |         const

The suggested code does not compile: https://godbolt.org/z/fGT9bvdza

Tested with 22.1.8

electricbrass avatar Aug 10 '26 01:08 electricbrass

@llvm/issue-subscribers-clang-tidy

Author: Mia McMahill (electricbrass)

```c++ void func(int* ptr1) { int* ptr2 = ptr1; *ptr2++ = 0; } ```
warning: pointee of variable 'ptr2' of type 'int *' can be declared 'const' [misc-const-correctness]
    3 |     int* ptr2 = ptr1;
      |     ^  
      |         const

The suggested code does not compile: https://godbolt.org/z/fGT9bvdza

Tested with 22.1.8

Also tested with 23.1.0-rc2. False positive is still present.

electricbrass avatar Aug 10 '26 03:08 electricbrass

I can try this

davidmenggx avatar Aug 10 '26 04:08 davidmenggx

godbolt repro https://godbolt.org/z/fxW8Ea1WT

vbvictor avatar Aug 10 '26 04:08 vbvictor