Skip to content

clang-tidy readability-function-size does not check lambda functions or constructors with no statements or lines. #131040

Open
@bartlettroscoe

Description

@bartlettroscoe

While working on extracting function metrics using the clang-tidy checks readability-function-size and readability-function-cognitive-complexity, I noticed that the readability-function-size check does not produce any output for lambda functions, but the readability-function-cognitive-complexity check does.

For example, readability-function-cognitive-complexity produces output for the following inline lambda function:

    for_each_token(entry, [&](const std::string& s) {
      const size_t pos = s.find("main");
      if (pos != std::string::npos) {
        found_main = true;
        main_col   = col_count;
      }
      ++col_count;
    });

showing a cognitive-complexity and nesting-level of 1, but the readability-function-size check does not produce any output.

It would be nice to be able to get metrics about the number of lines, statements, branches, parameters and variables with lambda functions.

Also, it seems that the readability-function-size check does not produce output for constructors with no statements in the body.
For example, the readability-function-size check produces no output for the inline constructor:

class any {
public:
  ...
  //! Copy constructor
  any(const any & other)
    : content(other.content ? other.content->clone() : 0)
    {}
  ...
};

Now, that function has a non-zero number of parameters, so the readability-function-size check should produce output showing that.

NOTE: I am using the following configuration file so these checks should produce output if any of these metrics are greater than zero:

Checks: '-*,readability-function-cognitive-complexity,readability-function-size'
CheckOptions:
  - key: readability-function-cognitive-complexity.Threshold
    value: '0'
  - key: readability-function-cognitive-complexity.DescribeBasicIncrements
    value: true
  - key: readability-function-cognitive-complexity.IgnoreMacros
    value: true
  - key: readability-function-size.LineThreshold
    value: '0'
  - key: readability-function-size.StatementThreshold
    value: '0'
  - key: readability-function-size.BranchThreshold
    value: '0'
  - key: readability-function-size.ParameterThreshold
    value: '0'
  - key: readability-function-size.NestingThreshold
    value: '0'
  - key: readability-function-size.VariableThreshold
    value: '0'

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions