Modernize the code base to C++11 standards and beyond.

Apply `clang-modernize` (based on Clang 3.6) transformations to the
codebase while making sure to support Clang>=3.4 and GCC>=4.8.

We apply the transformations in parallel to speed up the quite
time consuming process, and use our `clang-format` style file
to automatically format the code respecting our coding conventions.

We use the following self-explanatory transformations:

* AddOverride
* LoopConvert
* PassByValue
* ReplaceAutoPtr
* UseAuto
* UseNullptr

This required a `compile_commands.json` compilation database, e.g.

    ccmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=1

for CMake or check Bear for a Makefile based solution (or even Ninja).

    git ls-files -x '*.cpp|*.h' | \
      xargs -I{} -P $(nproc) clang-modernize -p build -final-syntax-check -format -style=file -summary -for-compilers=clang-3.4,gcc-4.8 -include . -exclude third_party {}

Boom!

References:

* http://clang.llvm.org/extra/clang-modernize.html
* http://clang.llvm.org/extra/ModernizerUsage.html
This commit is contained in:
Daniel J. Hofmann
2015-08-18 12:56:34 +02:00
parent 84e72ede72
commit 62b20769ee
24 changed files with 88 additions and 76 deletions
+1 -1
View File
@@ -146,7 +146,7 @@ bool GenerateDataStoreOptions(const int argc, const char *argv[], ServerPaths &p
}
// parse config file
ServerPaths::iterator path_iterator = paths.find("config");
auto path_iterator = paths.find("config");
if (path_iterator != paths.end() && boost::filesystem::is_regular_file(path_iterator->second) &&
!option_variables.count("base"))
{
+5 -5
View File
@@ -54,16 +54,16 @@ struct MatchingDebugInfo
}
osrm::json::Array states;
for (unsigned t = 0; t < candidates_list.size(); t++)
for (auto &elem : candidates_list)
{
osrm::json::Array timestamps;
for (unsigned s = 0; s < candidates_list[t].size(); s++)
for (unsigned s = 0; s < elem.size(); s++)
{
osrm::json::Object state;
state.values["transitions"] = osrm::json::Array();
state.values["coordinate"] = osrm::json::make_array(
candidates_list[t][s].first.location.lat / COORDINATE_PRECISION,
candidates_list[t][s].first.location.lon / COORDINATE_PRECISION);
state.values["coordinate"] =
osrm::json::make_array(elem[s].first.location.lat / COORDINATE_PRECISION,
elem[s].first.location.lon / COORDINATE_PRECISION);
state.values["viterbi"] =
osrm::json::clamp_float(osrm::matching::IMPOSSIBLE_LOG_PROB);
state.values["pruned"] = 0u;
+3 -2
View File
@@ -30,6 +30,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <exception>
#include <string>
#include <utility>
namespace osrm
{
@@ -37,14 +38,14 @@ class exception final : public std::exception
{
public:
explicit exception(const char *message) : message(message) {}
explicit exception(const std::string &message) : message(message) {}
explicit exception(std::string message) : message(std::move(message)) {}
private:
// This function exists to 'anchor' the class, and stop the compiler from
// copying vtable and RTTI info into every object file that includes
// this header. (Caught by -Wweak-vtables under Clang.)
virtual void anchor() const;
const char *what() const noexcept { return message.c_str(); }
const char *what() const noexcept override { return message.c_str(); }
const std::string message;
};
}
+1 -1
View File
@@ -243,7 +243,7 @@ inline unsigned GenerateServerProgramOptions(const int argc,
boost::program_options::notify(option_variables);
// parse config file
ServerPaths::iterator path_iterator = paths.find("config");
auto path_iterator = paths.find("config");
if (path_iterator != paths.end() && boost::filesystem::is_regular_file(path_iterator->second) &&
!option_variables.count("base"))
{