Skip to content

Linting the code #218

@sarahec

Description

@sarahec

I've been running a linter (clang-tidy) over the code for the past month and testing the the results of the recommended fixes. Are you interested in any or all of these? (I have all of these working in a private branch.)

  1. In C++, replace system headers with C++ headers where appropriate. Example <math.h> to <cmath>. The compiler uses its own bundled headers, so supplying a system header can lead to subtle bugs if there are layout differences between the two.

Updates to use C++11 syntax and features:

  1. Use nullptr to replace NULL and 0 as appropriate. This makes the use of null pointers more explicit.
  2. Use auto or auto* for when initializing objects where the type is obvious to avoid redundant declarations (Foo* foo = new Foo() to auto* foo = new Foo()
  3. Use override to label method overrides (instead of using virtual to mean both "can override" and "is overridden".) virtual override means you're overriding and someone else can override that. This also silences numerous compiler warnings in Clang.
  4. Replace typedef with using as appropriate. This is syntactic sugar that makes code easier to read. typedef std::map<BitVector, unsigned int> Dictionary; becomes using Dictionary = std::map<BitVector, unsigned int>;
  5. Use =default to have the compiler generate the appropriate code for ctors, dtors, copy/move, etc. when you have to override one of those but leave the rest alone. Example:

Old code:

Foo::Foo() {} // Are we overriding this to do nothing?
Foo::~Foo() {
  // log some message
}
Foo::Foo() =default; // "We had to declare this, and want the compiler to do its normal thing"
Foo::~Foo() {
  // log some message
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions