Skip to content

[clang-tidy] misc-const-correctness false positive with ->* operator #161913

@BenBudr

Description

@BenBudr

Minimal example of member access via pointer-to-member via pointer-to-object causing false positive:

struct S { int i; };

void a(int &) {}

int main()
{
  S s;
  S * sp = &s;
  a(sp->*(&S::i));
}
<source>:8:3: warning: pointee of variable 'sp' of type 'S *' can be declared 'const' [misc-const-correctness]
    8 |   S * sp = &s;
      |   ^
      |      const
1 warning generated.

Applying the suggested fix-it would cause a compilation error.

$ clang-tidy --version
LLVM (http://llvm.org/):
  LLVM version 21.1.2
  Optimized build.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions