roslint icon indicating copy to clipboard operation
roslint copied to clipboard

Unnamed function parameter mistaken for a C-style cast

Open toliver opened this issue 8 years ago • 3 comments

In the following file:

/*********************************************************************
 *  Copyright (c) XXXXX, Inc.
 *********************************************************************/
void *testFunction(void * /*unused_param*/)
{
}

Cpplint returns:

test.cpp:4:  Using C-style cast.  Use reinterpret_cast<void *>(...) instead  [readability/casting] [4]

In cpplint.py here there is already a case to cover this. But the problem is that this condition only gets checked if the line ends (among other things) with the character {, as you can see here.

So that case would be correctly caught if we use

/*********************************************************************
 *  Copyright (c) XXXXX, Inc.
 *********************************************************************/
void *testFunction(void * /*unused_param*/) {
}

but then of course we get an error about the position of the braces.

test.cpp:4:  when starting a new scope, { should be on a line by itself  [whitespace/braces] [4]

toliver avatar Sep 23 '16 12:09 toliver

Yes, this is a consequence of how we monkey patch cpplint.py to change it from Google's brace standard to the ROS one.

I'd welcome a patch to fix this.

mikepurvis avatar Sep 30 '16 20:09 mikepurvis

It's the same with postfix increment operator: TimeSpanHelper operator ++(int) {...} The message is "Using C-Style cast. Use static_cast(...) instead"

kmirny avatar Mar 05 '18 15:03 kmirny

I'm guessing there has been no patch for this issue. I'd suggest the C workaround for anyone that encounters this issue, to get the build without warnings and get cpplint to pass.

void *testFunction(SomeObject * p)
{
  (void) p;
}

ijnek avatar Jun 11 '21 14:06 ijnek