Request for Changes-40: clang modernize
[Request for Changes - 40] clang modernize
- Author: Manuel Grizonnet
- Submitted on dd.mm.yyyy
- Proposed target release 5.6
- Insert missing override keyword as a macro so that missing [optional] virtual identifiers can be easily added.
- Use ITK_NULLPTR to utilize c++11 features if available (nullptr)
- Remove double underscore in header guards (.txx & __otb*_h form) (cf http://stackoverflow.com/questions/228783/what-are-the-rules-about-using-an-underscore-in-a-c-identifier)
s This RFC activate optionally some C++11 features. It follows the same approach as ITK and use itk macro definitions empty by default if c++11 is not activated. It was generated using clang-tidy modernize checks. Commit messages gives commands and infos to reproduce the modifications.
C++11 added the keyword 'override' which in a member function declaration or definition ensures that the function is virtual and is overriding a virtual function from the base class.
Following ITK convention, I've used the macro ITK_OVERRIDE, empty by default if c++11 is not activated to maintain compatibility with older compilers.
The same principle has been applied to use ITK_USEPTR to check if a pointer is NULL.
- Remove double underscore in guards
From the 2003 C++ Standard: "Each name that contains a double underscore (_ _) or begins with an underscore followed by an uppercase letter (2.11) is reserved to the implementation for any use"
I've removed all double underscore in OTB guards (ITK has done the same)
- If this RFC is accepted coding style in OTB should be updated to indicate to developer:
- to use ITK_OVERRIDE macro if necessary
- to use ITK_NULLPTR macro if necessary
- avoid double underscore in header guards
- The modification has been done using an OTB compile with most modules activated but there should be some missing ITK_OVERRIDE. We could add them manually later by first setting a platform on cdash to see remaining "inconsistent-missing-override" warnings triggered by OTB
- There are lot of other useful clang checks that can be use in OTB to improve the code (sanitizer...). Moreover this RFC allows me to spot an incompatibility between OTB and clang 3.8 (already merges in release 5.4). I'll try to make some suggestions on the developer mailing list about the use of clang checks in the future.