[cfe-dev] clang-tidy attribute enforcement

Steve Sudit via cfe-dev cfe-dev at lists.llvm.org
Thu Sep 12 09:33:29 PDT 2019


I have a question about a clang-tidy feature that would be useful to me.

The feature would be to enforce the presence of an attribute on arguments
when it is present in the parameter.

So, for example, if a function is defined like:
  bool tryGet(const std::string& key, [[out]] std::string& value);

Then calls to it would need to have a matching `[[out]]` attribute, like:
  if (!directory.tryGet(k, [[out]] v)) {

If the attribute is omitted at the call site, a warning would be generated.
Likewise, if the attribute appeared at the call site, but not at the
function declaration, that would generate a warning.

No deeper enforcement is necessary. Presumably, which attributes would get
this enforcement would be configurable.

Is this or anything similar already supported? If not, could someone please
point me towards the steps I'd need to take get it added? This could either
be as a feature request for someone else to fulfill, or if necessary, my
own contribution to the project.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20190912/82560e02/attachment.html>


More information about the cfe-dev mailing list