Skip to content

Commit

Permalink
Add more compiler warning flags (#4061)
Browse files Browse the repository at this point in the history
* Add more compiler warning flags for GNU and Clang

* Resolve -Wdocumentation -Wno-documentation-deprecated-sync

* Resolve -Wzero-as-null-pointer-constant
  • Loading branch information
mwtoews authored Feb 21, 2024
1 parent 498d409 commit b57acc8
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 22 deletions.
35 changes: 29 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,30 +44,53 @@ set(CMAKE_CXX_VISIBILITY_PRESET hidden)
# Set warnings as variables, then store as cache options
set(PROJ_common_WARN_FLAGS # common only to GNU/Clang C/C++
-Wall
-Wdate-time
-Werror=format-security
-Werror=vla
-Wextra
-Wswitch
-Wformat
-Wmissing-declarations
-Wshadow
-Wswitch
-Wunused-parameter
-Wmissing-declarations
-Wformat
-Wformat-security
)
if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
set(PROJ_common_WARN_FLAGS ${PROJ_common_WARN_FLAGS}
-Wduplicated-cond
-Wduplicated-branches
-Wlogical-op
)
set(PROJ_C_WARN_FLAGS ${PROJ_common_WARN_FLAGS}
-Wmissing-prototypes
)
set(PROJ_CXX_WARN_FLAGS ${PROJ_common_WARN_FLAGS}
-Weffc++
-Wextra-semi
# -Wold-style-cast
-Woverloaded-virtual
-Wzero-as-null-pointer-constant
)
elseif("${CMAKE_C_COMPILER_ID}" MATCHES "Clang")
set(PROJ_common_WARN_FLAGS ${PROJ_common_WARN_FLAGS}
-Wcomma
-Wdeprecated
-Wdocumentation -Wno-documentation-deprecated-sync
-Wfloat-conversion
-Wlogical-op-parentheses
# -Wweak-vtables
)
set(PROJ_C_WARN_FLAGS ${PROJ_common_WARN_FLAGS}
-Wmissing-prototypes
-Wfloat-conversion
-Wc11-extensions
)
set(PROJ_CXX_WARN_FLAGS ${PROJ_common_WARN_FLAGS}
-Wfloat-conversion
-Weffc++
-Wextra-semi
# -Wold-style-cast
-Woverloaded-virtual
-Wshorten-64-to-32
-Wunused-private-field
-Wzero-as-null-pointer-constant
)
elseif("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")
add_definitions(/D_CRT_SECURE_NO_WARNINGS) # Eliminate deprecation warnings
Expand Down
3 changes: 1 addition & 2 deletions src/iso19111/operation/conversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1760,8 +1760,7 @@ ConversionNNPtr Conversion::createPopularVisualisationPseudoMercator(
* sphere at centerLat.
*
* This method is defined as
* <a
* href="https://epsg.org/coord-operation-method_1026/Mercator-Spherical.html">
* <a href="https://epsg.org/coord-operation-method_1026/Mercator-Spherical.html">
* EPSG:1026</a>.
*
* @param properties See \ref general_properties of the conversion. If the name
Expand Down
2 changes: 1 addition & 1 deletion test/fuzzers/proj_crs_to_crs_fuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ int main(int argc, char *argv[]) {
return 0;
} else {
int nRet = 0;
void *buf = NULL;
void *buf = nullptr;
int nLen = 0;
FILE *f = fopen(argv[1], "rb");
if (!f) {
Expand Down
22 changes: 11 additions & 11 deletions test/unit/gie_self_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ TEST(gie, cart_selftest) {
b = proj_trans(P, PJ_FWD, b);

/* Move it back to the default context */
proj_context_set(P, 0);
proj_context_set(P, nullptr);
ASSERT_EQ(pj_get_default_ctx(), P->ctx);

proj_context_destroy(ctx);
Expand All @@ -168,8 +168,8 @@ TEST(gie, cart_selftest) {
b = proj_trans(P, PJ_FWD, obs[1]);

n = proj_trans_generic(P, PJ_FWD, &(obs[0].lpz.lam), sz, 2,
&(obs[0].lpz.phi), sz, 2, &(obs[0].lpz.z), sz, 2, 0,
sz, 0);
&(obs[0].lpz.phi), sz, 2, &(obs[0].lpz.z), sz, 2,
nullptr, sz, 0);
ASSERT_EQ(n, 2U);

ASSERT_EQ(a.lpz.lam, obs[0].lpz.lam);
Expand Down Expand Up @@ -264,7 +264,7 @@ class gieTest : public ::testing::Test {
TEST_F(gieTest, proj_create_crs_to_crs) {
/* test proj_create_crs_to_crs() */
auto P = proj_create_crs_to_crs(PJ_DEFAULT_CTX, "epsg:25832", "epsg:25833",
NULL);
nullptr);
ASSERT_TRUE(P != nullptr);
PJ_COORD a, b;

Expand All @@ -288,7 +288,7 @@ TEST_F(gieTest, proj_create_crs_to_crs) {

/* we can also allow PROJ strings as a usable PJ */
P = proj_create_crs_to_crs(PJ_DEFAULT_CTX, "proj=utm +zone=32 +datum=WGS84",
"proj=utm +zone=33 +datum=WGS84", NULL);
"proj=utm +zone=33 +datum=WGS84", nullptr);
ASSERT_TRUE(P != nullptr);
proj_destroy(P);

Expand All @@ -303,7 +303,7 @@ TEST_F(gieTest, proj_create_crs_to_crs) {
TEST_F(gieTest, proj_create_crs_to_crs_EPSG_4326) {

auto P =
proj_create_crs_to_crs(PJ_DEFAULT_CTX, "EPSG:4326", "EPSG:32631", NULL);
proj_create_crs_to_crs(PJ_DEFAULT_CTX, "EPSG:4326", "EPSG:32631", nullptr);
ASSERT_TRUE(P != nullptr);
PJ_COORD a, b;

Expand All @@ -327,7 +327,7 @@ TEST_F(gieTest, proj_create_crs_to_crs_EPSG_4326) {
TEST_F(gieTest, proj_create_crs_to_crs_proj_longlat) {

auto P = proj_create_crs_to_crs(
PJ_DEFAULT_CTX, "+proj=longlat +datum=WGS84", "EPSG:32631", NULL);
PJ_DEFAULT_CTX, "+proj=longlat +datum=WGS84", "EPSG:32631", nullptr);
ASSERT_TRUE(P != nullptr);
PJ_COORD a, b;

Expand Down Expand Up @@ -729,7 +729,7 @@ static void test_time(const char *args, double tol, double t_in, double t_exp) {
PJ_COORD in, out;
PJ *P = proj_create(PJ_DEFAULT_CTX, args);

ASSERT_TRUE(P != 0);
ASSERT_TRUE(P != nullptr);

in = proj_coord(0.0, 0.0, 0.0, t_in);

Expand All @@ -741,7 +741,7 @@ static void test_time(const char *args, double tol, double t_in, double t_exp) {

proj_destroy(P);

proj_log_level(NULL, PJ_LOG_NONE);
proj_log_level(nullptr, PJ_LOG_NONE);
}

// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -773,7 +773,7 @@ static void test_date(const char *args, double tol, double t_in, double t_exp) {
PJ_COORD in, out;
PJ *P = proj_create(PJ_DEFAULT_CTX, args);

ASSERT_TRUE(P != 0);
ASSERT_TRUE(P != nullptr);

in = proj_coord(0.0, 0.0, 0.0, t_in);

Expand All @@ -782,7 +782,7 @@ static void test_date(const char *args, double tol, double t_in, double t_exp) {

proj_destroy(P);

proj_log_level(NULL, PJ_LOG_NONE);
proj_log_level(nullptr, PJ_LOG_NONE);
}

TEST(gie, unitconvert_selftest_date) {
Expand Down
4 changes: 2 additions & 2 deletions test/unit/test_c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4223,7 +4223,7 @@ TEST_F(CApi, proj_get_celestial_body_list_from_database) {

{
auto list =
proj_get_celestial_body_list_from_database(nullptr, nullptr, 0);
proj_get_celestial_body_list_from_database(nullptr, nullptr, nullptr);
ASSERT_NE(list, nullptr);
ASSERT_NE(list[0], nullptr);
ASSERT_NE(list[0]->auth_name, nullptr);
Expand Down Expand Up @@ -4668,7 +4668,7 @@ TEST_F(CApi, proj_context_copy_from_default) {

TEST_F(CApi, proj_context_clone) {
int new_init_rules =
proj_context_get_use_proj4_init_rules(NULL, 0) > 0 ? 0 : 1;
proj_context_get_use_proj4_init_rules(nullptr, 0) > 0 ? 0 : 1;
PJ_CONTEXT *new_ctx = proj_context_create();
EXPECT_NE(new_ctx, nullptr);
PjContextKeeper keeper_ctxt(new_ctx);
Expand Down

0 comments on commit b57acc8

Please sign in to comment.