Confusing non-const reference lint from cpplint

399 views
Skip to first unread message

Chris McDonald

unread,
Nov 17, 2021, 6:26:31 PM11/17/21
to c...@chromium.org, Mike Frysinger
Hello Chromium CXX folks,

While investigating b/206648376 on the Chrome OS side of things I ran into a situation where cpplint.py gives output that doesn't make sense to me: On the file kernel_feature_tool.h cpplint raises the lint 
kernel_feature_tool.h:107:  Is this a non-const reference? If so, make const or use a pointer: KernelFeature& kf  [runtime/references] [2]
but based on my reading of the current style guide a non-optional input/output parameter should be a (non-const) reference.

Am I understanding the style guide correctly here that this reference should be fine? Does this lint show up in Chromium as well or is there potentially a CPPLINT.cfg setting somewhere disabling this lint on the browser side?

Additionally cpplint seems to only raise this lint on the header file and not on kernel_feature_tool.cc, which was also confusing to me. Is this intentional?

I am not a Chromium CXX subject matter expert, so input to help clear up my understanding of what should be happening here is greatly appreciated.

Cheers,
Chris
--
I support flexible work schedules, and I’m sending this email now because it is within the hours I’m working today.  Please do not feel obliged to reply straight away - I understand that you will reply during the hours you work, which may not match mine.

Lei Zhang

unread,
Nov 17, 2021, 7:11:37 PM11/17/21
to Chris McDonald, c...@chromium.org, Mike Frysinger
The Google C++ style guide used to disallow non-const references, but
that changed within the last few years. I'm not sure how much
maintenance cpplint.py is getting, but it has not been updated to
match that. In Chromium, https://crrev.com/c/2248714 adjusted "git cl
lint" to drop this check.
> --
> You received this message because you are subscribed to the Google Groups "cxx" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
> To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAFpMKM7wdOxkJHsZ2Nc%3DMzZfxP4iviXRpEfD98V_Td0W0hh1Ow%40mail.gmail.com.

Joe Mason

unread,
Nov 18, 2021, 11:38:14 AM11/18/21
to Chris McDonald, c...@chromium.org, Mike Frysinger
On Wed, Nov 17, 2021 at 6:26 PM 'Chris McDonald' via cxx <c...@chromium.org> wrote:
Additionally cpplint seems to only raise this lint on the header file and not on kernel_feature_tool.cc, which was also confusing to me. Is this intentional?

I'm not 100% sure but this doesn't surprise me - the tool only needs to report the "error" at the function declaration in the header. Reporting it again at the definition in the .cc would be a duplicate.

If there was a function that was *only* referenced in the .cc (like a local helper function in an anonymous namespace) that got skipped by the lint, that would be surprising.
Reply all
Reply to author
Forward
0 new messages