Issue 178880
Summary clang-tidy check misc-const-correctness suggests bad autofix on arrays
Labels clang-tidy
Assignees
Reporter sfc-gh-sgiesecke
    On an array of pointers-to-const, misc-const-correctness suggests a bad autofix, placing the extra `const` at the wrong location which causes a syntax error:
```
void foo() { const char*  foo[] = {"a", "b"}; foo[0] = "c"; }
```
produces the diagnostic
```
<source>:36:14: warning: pointee of variable 'foo' of type 'const char *[2]' can be declared 'const' [misc-const-correctness]
   36 | void foo() { const char*  foo[] = {"a", "b"}; foo[0] = "c"; }
      |              ^         
      | const
```
and when the resulting yaml is applied using clang-apply-replacements this becomes:
```
void foo() { const const char* foo[] = {"a", "b"}; foo[0] = "c"; }
```
instead of 
```
void foo() { const char* const  foo[] = {"a", "b"}; foo[0] = "c"; }
```
It's somewhat confusing that the position of the caret and the position of the added `const` are inconsistent. 
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to