Skip to content

clang-tidy readability-non-const-parameter false positive with Obj-C #140492

Open
@seanm

Description

@seanm

With the following Obj-C code:

#import <AppKit/AppKit.h>

static void RRGetRGBFromColour(NSColor* inColour, double* outRed, double* outGreen, double* outBlue)
{
  NSColor* colour = [inColour colorUsingColorSpace:[NSColorSpace genericRGBColorSpace]];
  [colour getRed:outRed green:outGreen blue:outBlue alpha:nil];
}

clang-tidy incorrectly says:

/Users/sean/test.m:3:59: warning: pointer parameter 'outRed' can be pointer to const [readability-non-const-parameter]
    3 | static void RRGetRGBFromColour(NSColor* inColour, double* outRed, double* outGreen, double* outBlue)
      |                                                           ^
      |                                                   const

But those 3 double* can't be const, the whole point is that data is written at those 3 addresses. If I use -fix the resulting change indeed does not compile.

Here's clang-check --ast-dump for the function:

`-FunctionDecl 0x12b261890 </Users/sean/test.m:3:1, line:6:1> line:3:13 RRGetRGBFromColour 'void (NSColor *__strong, double *, double *, double *)' static
  |-ParmVarDecl 0x12b2615c0 <col:32, col:41> col:41 used inColour 'NSColor *__strong' destroyed
  |-ParmVarDecl 0x12b261640 <col:51, col:59> col:59 used outRed 'double *'
  |-ParmVarDecl 0x12b2616c0 <col:67, col:75> col:75 used outGreen 'double *'
  |-ParmVarDecl 0x12b261740 <col:85, col:93> col:93 used outBlue 'double *'
  `-CompoundStmt 0x12b261b30 <line:4:1, line:6:1>
    `-ObjCMessageExpr 0x12b261ad0 <line:5:2, col:63> 'void' selector=getRed:green:blue:alpha:
      |-ImplicitCastExpr 0x12b261a58 <col:3> 'NSColor *' <LValueToRValue>
      | `-DeclRefExpr 0x12b261958 <col:3> 'NSColor *__strong' lvalue ParmVar 0x12b2615c0 'inColour' 'NSColor *__strong'
      |-ImplicitCastExpr 0x12b261a70 <col:19> 'double *' <LValueToRValue>
      | `-DeclRefExpr 0x12b261978 <col:19> 'double *' lvalue ParmVar 0x12b261640 'outRed' 'double *'
      |-ImplicitCastExpr 0x12b261a88 <col:32> 'double *' <LValueToRValue>
      | `-DeclRefExpr 0x12b261998 <col:32> 'double *' lvalue ParmVar 0x12b2616c0 'outGreen' 'double *'
      |-ImplicitCastExpr 0x12b261aa0 <col:46> 'double *' <LValueToRValue>
      | `-DeclRefExpr 0x12b2619b8 <col:46> 'double *' lvalue ParmVar 0x12b261740 'outBlue' 'double *'
      `-ImplicitCastExpr 0x12b261ab8 </Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk/usr/include/sys/_types.h:64:23, col:33> 'CGFloat * _Nullable':'CGFloat *' <NullToPointer>
        `-ParenExpr 0x12b261a38 <col:23, col:33> 'void *'
          `-CStyleCastExpr 0x12b261a10 <col:24, col:32> 'void *' <NullToPointer>
            `-IntegerLiteral 0x12b2619d8 <col:32> 'int' 0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions