george.burgess.iv created this revision.
george.burgess.iv added a reviewer: alexfh.
george.burgess.iv added a subscriber: cfe-commits.
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.
http://reviews.llvm.org/D18765
Files:
clang-tidy/readability/AvoidConstParamsInDecls.cpp
test/clang-tidy/readability-avoid-const-params-in-decls.cpp
Index: test/clang-tidy/readability-avoid-const-params-in-decls.cpp
===
--- test/clang-tidy/readability-avoid-const-params-in-decls.cpp
+++ test/clang-tidy/readability-avoid-const-params-in-decls.cpp
@@ -65,6 +65,8 @@
void NF6(const int *const) {}
void NF7(int, const int) {}
void NF8(const int, const int) {}
+// pass_object_size requires a const pointer param in definitions.
+void NF9(const char *const __attribute__((pass_object_size(0 {}
// Do not match on other stuff
void NF(const alias_type& i);
@@ -76,3 +78,6 @@
void NF(const int*);
void NF(const int* const*);
void NF(alias_const_type);
+// While pass_object_size only requires a const pointer param in definitions,
+// it's probably best to not complain at users for using it in a decl.
+void NF(const char *const __attribute__((pass_object_size(0;
Index: clang-tidy/readability/AvoidConstParamsInDecls.cpp
===
--- clang-tidy/readability/AvoidConstParamsInDecls.cpp
+++ clang-tidy/readability/AvoidConstParamsInDecls.cpp
@@ -31,7 +31,8 @@
void AvoidConstParamsInDecls::registerMatchers(MatchFinder *Finder) {
const auto ConstParamDecl =
- parmVarDecl(hasType(qualType(isConstQualified(.bind("param");
+ parmVarDecl(hasType(qualType(isConstQualified())),
+ unless(hasAttr(clang::attr::PassObjectSize))).bind("param");
Finder->addMatcher(functionDecl(unless(isDefinition()),
has(typeLoc(forEach(ConstParamDecl
.bind("func"),
Index: test/clang-tidy/readability-avoid-const-params-in-decls.cpp
===
--- test/clang-tidy/readability-avoid-const-params-in-decls.cpp
+++ test/clang-tidy/readability-avoid-const-params-in-decls.cpp
@@ -65,6 +65,8 @@
void NF6(const int *const) {}
void NF7(int, const int) {}
void NF8(const int, const int) {}
+// pass_object_size requires a const pointer param in definitions.
+void NF9(const char *const __attribute__((pass_object_size(0 {}
// Do not match on other stuff
void NF(const alias_type& i);
@@ -76,3 +78,6 @@
void NF(const int*);
void NF(const int* const*);
void NF(alias_const_type);
+// While pass_object_size only requires a const pointer param in definitions,
+// it's probably best to not complain at users for using it in a decl.
+void NF(const char *const __attribute__((pass_object_size(0;
Index: clang-tidy/readability/AvoidConstParamsInDecls.cpp
===
--- clang-tidy/readability/AvoidConstParamsInDecls.cpp
+++ clang-tidy/readability/AvoidConstParamsInDecls.cpp
@@ -31,7 +31,8 @@
void AvoidConstParamsInDecls::registerMatchers(MatchFinder *Finder) {
const auto ConstParamDecl =
- parmVarDecl(hasType(qualType(isConstQualified(.bind("param");
+ parmVarDecl(hasType(qualType(isConstQualified())),
+ unless(hasAttr(clang::attr::PassObjectSize))).bind("param");
Finder->addMatcher(functionDecl(unless(isDefinition()),
has(typeLoc(forEach(ConstParamDecl
.bind("func"),
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits