Skip to content

misc-const-correctness suggests const on pointer to array even if disabled #56749

Closed
@firewave

Description

@firewave
static void f()
{
    const char * a[] = {"", ""};
}
<source>:3:5: warning: variable 'a' of type 'const char *[2]' can be declared 'const' [misc-const-correctness]
    const char * a[] = {"", ""};
    ^
                 const

https://godbolt.org/z/e646rPo99

According to https://clang.llvm.org/extra/clang-tidy/checks/misc/const-correctness.html WarnPointersAsValues is disabled by default. It seems this option is not being used when it applies to arrays (that's the only case I have seen it with).

Also the fix-it hint is placed on the existing const which makes this look like a false positive (see the "swiggle" in godbolt). I think that actually should to point before the a instead.

The documentation of WarnPointersAsValues could be bit more straightforward and including a proper before/after example would also be helpful. I knew what it was supposed to do but I really didn't get it from the documentation.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions