-
Notifications
You must be signed in to change notification settings - Fork 50
Open
Description
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.)
- 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:
- Use
nullptrto replace NULL and 0 as appropriate. This makes the use of null pointers more explicit. - Use
autoorauto*for when initializing objects where the type is obvious to avoid redundant declarations (Foo* foo = new Foo()toauto* foo = new Foo() - Use
overrideto label method overrides (instead of usingvirtualto mean both "can override" and "is overridden".)virtual overridemeans you're overriding and someone else can override that. This also silences numerous compiler warnings in Clang. - Replace
typedefwithusingas appropriate. This is syntactic sugar that makes code easier to read.typedef std::map<BitVector, unsigned int> Dictionary;becomesusing Dictionary = std::map<BitVector, unsigned int>; - Use
=defaultto 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
Labels
No labels