Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang-tidy v. -Weffc++ #54

Open
springmeyer opened this issue Apr 24, 2018 · 1 comment
Open

clang-tidy v. -Weffc++ #54

springmeyer opened this issue Apr 24, 2018 · 1 comment

Comments

@springmeyer
Copy link
Contributor

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 #37 (comment), 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

  • -Weffc++ will warn on all class members not explicitly initialized in the initializer list
  • clang-tidy will automatically remove variables from the initializer list that have default constructors

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

  • let clang-tidy win
  • recommend no longer using g++ with -Weffc++
  • figure out what alternative way we can catch when members, without default initializers, are uninitialized (without needing to use -Weffc++). Maybe another clang-tidy check?
@springmeyer
Copy link
Contributor Author

Looks like using C++11 brace initialization in the class definition works to appease -Weffc++ and clang-tidy like mapbox/node-cpp-skel@7a97785

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant