mapbox / cpp

C++ @ Mapbox
108 stars 17 forks source link

clang-tidy v. -Weffc++ #54

Open springmeyer opened 6 years ago

springmeyer commented 6 years ago

Context

Recent versions of clang-tidy added readability-redundant-member-init: https://clang.llvm.org/extra/clang-tidy/checks/readability-redundant-member-init.html

This is handy! When a class member has a default initializer it is redundent to initialize it in the member list.

But, because some types don't have default initializers, forgetting to initialize them in the member list (or using c++11 initialization in the class definition) can lead to serious trouble like mapbox/wagyu#69 - refs mapbox/wagyu#70.

So, this is the reason, at https://github.com/mapbox/cpp/issues/37#issuecomment-336200744, that we recommend using g++ and the -Weffc++ flag because it can catch this (note, clang++ plus -Weffc++ cannot):

-Weffc++ - useful when building with g++ (does not do much with clang++). With g++ it can catch uninitialized class members and prevent crashes like mapbox/wagyu#69 - refs mapbox/wagyu#70

Problem

So, the two will fight: causing each other warnings. For this reason I think we should likely:

springmeyer commented 6 years ago

Looks like using C++11 brace initialization in the class definition works to appease -Weffc++ and clang-tidy like https://github.com/mapbox/node-cpp-skel/commit/7a97785cb9828fe107f23d1b5ef9cd7efb3b41f0