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

Add more default warnings #18

Merged
merged 5 commits into from
Oct 16, 2017
Merged

Add more default warnings #18

merged 5 commits into from
Oct 16, 2017

Conversation

springmeyer
Copy link
Contributor

Starts adhering to mapbox/cpp#37

@springmeyer springmeyer mentioned this pull request Oct 12, 2017
@springmeyer springmeyer requested a review from GretaCB October 16, 2017 05:01
@springmeyer
Copy link
Contributor Author

@GretaCB - would love a review here before merging.

@springmeyer
Copy link
Contributor Author

Note: most of the work fixing the errors (that came up from more warnings) was done in #19 where I've added many commit comments for context.

# Note: -D_GLIBCXX_USE_CXX11_ABI=0 is needed to support mason packages that are precompiled libs
# Currently we only depend on a header only library, but this will help avoid issues when more libs are added via mason
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OPTIMIZATION_FLAGS} -Wall -Wextra -pedantic -Wsign-compare -Wconversion -Wshadow")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OPTIMIZATION_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=0 ${DESIRED_WARNINGS}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@springmeyer what is D_GLIBCXX_USE_CXX11_ABI used for? a boolean setting for GCC to use a specific c++ version?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch. Did not realize I added this flag in this PR. It should have been there all along (as we make mention of it in the code comment above). More background on it is at https://github.com/mapbox/node-cpp-skel/blob/3f7d2c4bcf3a6162312accbf3554ac17ecbbb407/common.gypi#L6. And https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html. In short: until mason supports building against both "ABIS" we need to this flag to avoid edge case linking errors on different linux versions when using mason binary C++ packages. Currently in gzip-hpp we don't link to any mason packages that are C++, so this is technically not needed. But we put it in hpp-skel to avoid this pitfall for downstream users that might add c++ mason binary packages, and therefore my copy/paste here brought it in.

@@ -17,9 +17,12 @@ else()
message("-- Configuring release build")
endif()

# Enable extra warnings to adhere to https://github.com/mapbox/cpp/issues/37
set(DESIRED_WARNINGS "-Wall -Wextra -Wconversion -Wunreachable-code -Wuninitialized -pedantic-errors -Wold-style-cast -Wno-error=unused-variable -Wshadow -Wfloat-equal")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These represent 🍇 from mapbox/cpp#37 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, 🍇 and 🍊 (although I now realize I missed -Weffc++)

@@ -31,7 +33,7 @@ std::string compress(const char* data,
{
throw std::runtime_error("deflate init failed");
}
deflate_s.next_in = (Bytef*)data;
deflate_s.next_in = reinterpret_cast<z_const Bytef*>(data);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was(Bytef*)data flagged as an error?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah seeing #19 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -0,0 +1,5 @@
#pragma once
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the vision of this file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One single place to define ZLIB_CONST (without this it would need to be defined in every header before zlib.h is included. This consolidates enabling the const type inside zlib in one place.

@@ -1,4 +1,7 @@
#include <cstdlib>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read http://www.cplusplus.com/reference/cstdlib/, but still not sure why this header is needed here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, seeing #19 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed for uint8_t. Without it, this header would not compile on its own. So this is an IWYU fix, aka include what you use.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More details on that at https://github.com/include-what-you-use/include-what-you-use. clang-tidy can also flag when headers are depending on types but not including the header for them.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is include-what-you-use automatically included in clang-tidy? Or are you using it here as a general good practice?

Also, is tidy succeeding for you locally? I'm getting errors:

/Users/carol/dev/gzip-hpp/mason_packages/osx-x86_64/benchmark/1.2.0/include/benchmark/benchmark.h:832:3: error: Potential memory leak [clang-analyzer-cplusplus.NewDeleteLeaks,-warnings-as-errors]
  return internal::RegisterBenchmarkInternal(
  ^
/Users/carol/dev/gzip-hpp/bench/run.cpp:47:5: note: Taking false branch
    if (!stream.is_open())
    ^
Suppressed 10135 warnings (10134 in non-user code, 1 NOLINT).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
1 warning treated as error
21620 warnings generated.
/Users/carol/dev/gzip-hpp/test/test.cpp:28:5: error: consider replacing 'unsigned long' with 'uint64' [google-runtime-int,-warnings-as-errors]
    unsigned long l = 2000000001;
    ^
Suppressed 21619 warnings (21619 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
1 warning treated as error
Applying fixes ...

@GretaCB
Copy link
Contributor

GretaCB commented Oct 16, 2017

Sweet, thanks for running this out @springmeyer . Curious if these default flags should be added to hpp-skel as well

@springmeyer
Copy link
Contributor Author

Thanks for the review @GretaCB - will merge now.

Curious if these default flags should be added to hpp-skel as well

Yes: mapbox/hpp-skel#52

@springmeyer springmeyer merged commit 2b39bfb into master Oct 16, 2017
@springmeyer springmeyer deleted the better-default-warnings branch October 16, 2017 18:50
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

Successfully merging this pull request may close these issues.

2 participants