Thanks to visit codestin.com
Credit goes to github.com

Skip to content

False positive for whitespace/indent_namespace with member initializer lists #372

@marinedayo

Description

@marinedayo

I have encountered a few patterns of false positives for whitespace/indent_namespace.
All of them occur with the member initializer lists, which have multiple lines.

I hope this will be helpful for improvement.

cpplint version: 2.0.2

$ cpplint --version
Cpplint fork (https://github.com/cpplint/cpplint)
cpplint 2.0.2
Python 3.12.9 (main, Feb  4 2025, 14:38:38) [Clang 16.0.0 (clang-1600.0.26.6)]

case1: constructor with an empty body

namespace cpplint_issue {

class TestIndentNamespaceWithEmptyBody {
 public:
  explicit TestIndentNamespaceWithEmptyBody(const int a);

 private:
  const int number;
  const int looooooong_attr1;
  const int looooooong_attr2;
  const int looooooong_attr3;
  const int looooooong_attr4;
};

TestIndentNamespaceWithEmptyBody::TestIndentNamespaceWithEmptyBody(const int a)
    : number(a),
      looooooong_attr1(0),
      looooooong_attr2(0),
      looooooong_attr3(0),
      looooooong_attr4(0) {}  // <- This line causes a false positive.

}  // namespace cpplint_issue

case2: use inline specifier

namespace cpplint_issue {

class TestIndentNamespaceWithInline {
 public:
  explicit TestIndentNamespaceWithInline(const int a);

 private:
  const int number;
  const int looooooong_attr1;
  const int looooooong_attr2;
  const int looooooong_attr3;
  const int looooooong_attr4;
};

inline TestIndentNamespaceWithInline::TestIndentNamespaceWithInline(const int a)
    : number(a),             // <- These lines cause a false positive.
      looooooong_attr1(0),   // <-
      looooooong_attr2(0),   // <-
      looooooong_attr3(0),   // <-
      looooooong_attr4(0) {  // <-
  // do nothing
}

}  // namespace cpplint_issue

case3: with a struct variable

namespace cpplint_issue {

struct Params {
  int number;
};

class TestIndentNamespaceWithStructMember {
 public:
  explicit TestIndentNamespaceWithStructMember(const int a);

 private:
  const Params params;
  const int looooooong_attr1;
  const int looooooong_attr2;
  const int looooooong_attr3;
  const int looooooong_attr4;
};

TestIndentNamespaceWithStructMember::TestIndentNamespaceWithStructMember(const int a)
    : params({a}),
      looooooong_attr1(0),   // <- These lines cause a false positive.
      looooooong_attr2(0),   // <-
      looooooong_attr3(0),   // <-
      looooooong_attr4(0) {  // <-
  // do nothing
}

}  // namespace cpplint_issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions