Skip to content

clang-tidy bugprone-unused-return-value does not work for Obj-C methods #141292

Open
@seanm

Description

@seanm

Given:

#import <Foundation/Foundation.h>

int main (void)
{
  [NSString alloc]; // expect warning: return value ignored
		
  return 0;
}

Here I want a warning for ignoring the return value of alloc. (Like ignoring the return value of malloc, this is almost always wrong.)

bugprone-unused-return-value has an option CheckedFunctions which you can set to the regex .* to get warnings for all ignored return values. This indeed works for C/C++ functions, even in Obj-C source files. I can't get it to work for Obj-C methods though.

I don't know the LLVM codebase at all, but was learning about clang-tidy, and looked at UnusedReturnValueCheck.cpp and I wonder if this is because it matches with callExpr and ObjCMessageExpr is not a subclass of that.

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