This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Improved documentation for readability-function-size
ClosedPublic

Authored by felix642 on Aug 28 2023, 5:36 PM.

Details

Reviewers
njames93
PiotrZSL
Summary

The documentation would say that that default value for most parameters is -1.
But since the parameter used in clang-tidy is an unsigned the value would get implicitly converted to 4294967295.

If a user tried to use -1 to disable this check he would receive an error saying that
the parameter is invalid.

Diff Detail

Event Timeline

felix642 created this revision.Aug 28 2023, 5:36 PM
felix642 requested review of this revision.Aug 28 2023, 5:36 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 28 2023, 5:36 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
felix642 updated this revision to Diff 554122.Aug 28 2023, 5:36 PM

Fixed commit message

felix642 updated this revision to Diff 554124.Aug 28 2023, 5:37 PM

Linked issue

PiotrZSL accepted this revision.Aug 28 2023, 11:31 PM

Change is ok. Interesting thing is that we got more of such issues in many checks. I'm thinking, maybe support for optional fields is needed, fields that can accept integer or false/no values.

This revision is now accepted and ready to land.Aug 28 2023, 11:31 PM

We can already disable those options if we don't define them in the config. Adding the possibility to provide optional values seems redundant to me. Do you see any reason why we would absolutely need to add this option to the config if we want to disable it?

We can already disable those options if we don't define them in the config. Adding the possibility to provide optional values seems redundant to me. Do you see any reason why we would absolutely need to add this option to the config if we want to disable it?

a) If you use config file inheritance, when one config file define it, and other that inherit it (or command line) want to disable such option.
b) When we use --dump-config then it will be printed anyway.

In that case, I agree with you, it would be helpful to add this feature. I think supporting an empty value rather than a boolean is preferable. We should maybe do that in another Differential though. I can open an issue on github and I'll open another diff when I'm ready. What do you think?

In that case, I agree with you, it would be helpful to add this feature. I think supporting an empty value rather than a boolean is preferable. We should maybe do that in another Differential though. I can open an issue on github and I'll open another diff when I'm ready. What do you think?

Yes this should be done as a separate change.
Probably something like this would be needed in ClangTidyCheck.h.

template <typename T>
std::enable_if_t<std::is_integral_v<T>, std::optional<T>> get(StringRef LocalName, std::optional<T> Default) const {
      if (std::optional<StringRef> Value = get(LocalName)) {
        if (value == "none" || value == "null" || value == "false" || value == "") // and -1 for unsigned types for backward combability
              return std::nullopt;
        T Result{};
        if (!StringRef(*Value).getAsInteger(10, Result))
          return Result;
        diagnoseBadIntegerOption(NamePrefix + LocalName, *Value);
      }
      return Default;
 }

And storing would need to be updated in similar way.

PiotrZSL closed this revision.Oct 9 2023, 11:00 AM

Obsolete. No longer needed after D159436