This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Don't complain about const pass_object_size params in declarations
AbandonedPublic

Authored by george.burgess.iv on Apr 4 2016, 11:19 AM.

Details

Reviewers
alexfh
Summary

This patch seems trivial, but I've never touched clang-tidy before, so I'm just making sure I didn't miss something obvious. :)


Clang has a parameter attribute called pass_object_size, which requires that its parameter's type be const. This restriction only applies at function definitions. e.g.

void foo(void *p __attribute__((pass_object_size(0))); // this is a decl; const isn't required.
void foo(void *const p __attribute__((pass_object_size(0))) {} // const is required; this is a def.

readability-avoid-const-params-in-decls will complain if you put const in the decl. Given that clang gives you an error unless you use const in the def, I don't think it's clearly a bad thing to use const in the decl. This patch makes said checker not complain about const params with the pass_object_size attribute.

Diff Detail

Event Timeline

george.burgess.iv retitled this revision from to [clang-tidy] Don't complain about const pass_object_size params in declarations.
george.burgess.iv updated this object.
george.burgess.iv added a reviewer: alexfh.
george.burgess.iv updated this object.
george.burgess.iv added a subscriber: cfe-commits.
alexfh requested changes to this revision.Apr 5 2016, 2:06 AM
alexfh edited edge metadata.

There's a principal difference between top-level const on parameters in definitions and in declarations: in definitions const has an effect, as it makes the variable constant, but in declarations it has absolutely no effect. Since declarations usually represent the function's interface, and top-level const on parameters doesn't change the function's signature, it's considered useless and misleading when used on declarations. Long story short, I don't see any value in this change.

This revision now requires changes to proceed.Apr 5 2016, 2:06 AM
alexfh added a comment.Apr 5 2016, 2:13 AM

To clarify: the pass_object_size attribute is not the only reason to mark parameter const in the definition. However, there's no reason to also mark them const in declarations, since that const is not a part of the function's interface.

george.burgess.iv abandoned this revision.Apr 5 2016, 9:54 AM

There's a principal difference between top-level const on parameters in definitions and in declarations: in definitions const has an effect, as it makes the variable constant, but in declarations it has absolutely no effect [...] it's considered useless and misleading when used on declarations

Yup! I didn't realize it was considered misleading, though -- good to know.

Long story short, I don't see any value in this change.

Yeah, the more I think about it, the more I agree that this doesn't clearly add value, so I'll drop it. Thanks for the review :)