Add and fix compiler warnings (#718)
* Add and remove compiler warning compile options
Add some new compiler warnings. Some of those does not build clean so
ignore them for now. This also helps if some user use those options so
we ignore those for them also.
Also remove following ignores as they do not produce any warnings:
- Wno-attributes
- Wno-long-long
- Wno-implicit-fallthrough
* Fix -Wmissing-declarations compiler warnings
Fix new -Wmissing-declarations compiler warnings. I tried to look which
should be in headers and which should be static. Might be that some
statics should be in header as it is not easy to choose if something
should be exported or not.
* Fix -Wmissing-field-initializers compiler warnings
If we use { { 0 } } compiler thinks we might have mean that we only
meant initialize first member of struct or have forgotton to add second
one. We could do { { 0 }, 0 } but we can just do { 0 } which tells
compiler that hey just intialize this whole thing to zero.
* tests: Fix couple -Wfloat-conversion warnings
Add f prefix to floating point numbers to get some double to float
warnings away.
* ci: Make warnings as errors with cmake main build
To keep repo more clean from warnings use Werror flag when building main
project.
Windows should need -DCMAKE_C_FLAGS="/WX" but we have not ignore errors
for that yet so let's not yet take it in use.
* ci: Build also tests in matrix build
Enable also tests to be builded in our main matrix build. This way tests
will be builded also with clang and in future also with MSVC. We also
keep build very clean now as all warnings as catched.
With this we can also take out -Werror from compile_options as we add
that in CI. It is not good practice to keep that option always on. It
makes development lot harder. See example this blog post [1].
[1]: https://embeddedartistry.com/blog/2017/05/22/werror-is-not-your-friend/
* getevent: Deprecate getevent_encode_apdu()
Steve suggested that we should deprecate getevent_encode_apdu() [1].
Suggested-by: Steve Karg
[1]: https://github.com/bacnet-stack/bacnet-stack/pull/718#discussion_r1715821735
---------
Co-authored-by: Kari Argillander <kari.argillander@fidelix.com>
This commit is contained in:
+21
-8
@@ -12,20 +12,33 @@ endif()
|
||||
|
||||
# Set the compiler options
|
||||
if (CMAKE_C_COMPILER_ID MATCHES "Clang" OR CMAKE_C_COMPILER_ID MATCHES "GNU")
|
||||
add_definitions(-fprofile-arcs -ftest-coverage)
|
||||
add_compile_options(-g -O0 -W -fprofile-arcs -ftest-coverage)
|
||||
add_compile_options(-g -O0 -fprofile-arcs -ftest-coverage)
|
||||
# enable all relevant warnings that find bugs
|
||||
add_compile_options(-Werror)
|
||||
add_compile_options(-Wall -Wextra -pedantic)
|
||||
add_compile_options(-Wfloat-equal -Wconversion)
|
||||
add_compile_options(-Wredundant-decls -Wswitch-default)
|
||||
add_compile_options(-Wunused-variable -Wdouble-promotion)
|
||||
add_compile_options(-Wfloat-conversion -Wdouble-promotion)
|
||||
add_compile_options(-Wredundant-decls -Wmissing-declarations)
|
||||
add_compile_options(-Wswitch-default)
|
||||
add_compile_options(-Wunused-variable)
|
||||
add_compile_options(-Wcast-qual)
|
||||
|
||||
# don't warn about conversion, sign, compares, long long and attributes
|
||||
# since they are common in embedded
|
||||
add_compile_options(-Wno-sign-conversion -Wno-conversion)
|
||||
add_compile_options(-Wno-sign-compare -Wno-long-long -Wno-attributes)
|
||||
# don't warn about implicit fallthrough since it's common in network protocols
|
||||
add_compile_options(-Wno-implicit-fallthrough)
|
||||
add_compile_options(-Wno-sign-compare)
|
||||
|
||||
# Just noise from clang
|
||||
if (CMAKE_C_COMPILER_ID MATCHES "Clang" OR CMAKE_C_COMPILER_ID MATCHES "AppleClang")
|
||||
add_compile_options(-Wno-gnu-zero-variadic-macro-arguments)
|
||||
endif()
|
||||
|
||||
# Should be fixed in the future
|
||||
add_compile_options(-Wno-cast-qual)
|
||||
add_compile_options(-Wno-double-promotion)
|
||||
add_compile_options(-Wno-float-conversion)
|
||||
add_compile_options(-Wno-missing-declarations)
|
||||
add_compile_options(-Wno-unused-but-set-variable)
|
||||
|
||||
add_link_options(-fprofile-arcs -ftest-coverage)
|
||||
endif()
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
#if defined(CONFIG_ZTEST_NEW_API)
|
||||
ZTEST(bacpropstates_tests, testPropStates)
|
||||
#else
|
||||
void testPropStates(void)
|
||||
static void testPropStates(void)
|
||||
#endif
|
||||
{
|
||||
BACNET_PROPERTY_STATE data = { 0 };
|
||||
|
||||
@@ -49,7 +49,7 @@ static void test_object_command(void)
|
||||
pAction->Property_Array_Index = BACNET_ARRAY_ALL;
|
||||
pAction->Priority = 16;
|
||||
pAction->Value.tag = BACNET_APPLICATION_TAG_REAL;
|
||||
pAction->Value.type.Real = 3.14159;
|
||||
pAction->Value.type.Real = 3.14159f;
|
||||
pAction->Post_Delay = 0;
|
||||
pAction->Quit_On_Failure = false;
|
||||
pAction->Write_Successful = false;
|
||||
|
||||
@@ -109,31 +109,31 @@ static void test_color_rgb_xy(void)
|
||||
|
||||
/* functions without gamma correction */
|
||||
color_rgb_from_ascii(&red, &green, &blue, "black");
|
||||
test_color_rgb_xy_unit(red, green, blue, 0.0, 0.0, 0);
|
||||
test_color_rgb_xy_unit(red, green, blue, 0.0f, 0.0f, 0);
|
||||
color_rgb_from_ascii(&red, &green, &blue, "white");
|
||||
test_color_rgb_xy_unit(red, green, blue, 0.313, 0.329, 255);
|
||||
test_color_rgb_xy_unit(red, green, blue, 0.313f, 0.329f, 255);
|
||||
color_rgb_from_ascii(&red, &green, &blue, "blue");
|
||||
test_color_rgb_xy_unit(red, green, blue, 0.157, 0.017, 5);
|
||||
test_color_rgb_xy_unit(red, green, blue, 0.157f, 0.017f, 5);
|
||||
color_rgb_from_ascii(&red, &green, &blue, "green");
|
||||
test_color_rgb_xy_unit(red, green, blue, 0.115, 0.826, 95);
|
||||
test_color_rgb_xy_unit(red, green, blue, 0.115f, 0.826f, 95);
|
||||
color_rgb_from_ascii(&red, &green, &blue, "red");
|
||||
test_color_rgb_xy_unit(red, green, blue, 0.735, 0.265, 59);
|
||||
test_color_rgb_xy_unit(red, green, blue, 0.735f, 0.265f, 59);
|
||||
color_rgb_from_ascii(&red, &green, &blue, "maroon");
|
||||
test_color_rgb_xy_unit(red, green, blue, 0.735, 0.265, 29);
|
||||
test_color_rgb_xy_unit(red, green, blue, 0.735f, 0.265f, 29);
|
||||
|
||||
/* functions with gamma correction */
|
||||
color_rgb_from_ascii(&red, &green, &blue, "black");
|
||||
test_color_rgb_xy_gamma_unit(red, green, blue, 0.0, 0.0, 0);
|
||||
test_color_rgb_xy_gamma_unit(red, green, blue, 0.0f, 0.0f, 0);
|
||||
color_rgb_from_ascii(&red, &green, &blue, "white");
|
||||
test_color_rgb_xy_gamma_unit(red, green, blue, 0.313, 0.329, 255);
|
||||
test_color_rgb_xy_gamma_unit(red, green, blue, 0.313f, 0.329f, 255);
|
||||
color_rgb_from_ascii(&red, &green, &blue, "blue");
|
||||
test_color_rgb_xy_gamma_unit(red, green, blue, 0.157, 0.017, 5);
|
||||
test_color_rgb_xy_gamma_unit(red, green, blue, 0.157f, 0.017f, 5);
|
||||
color_rgb_from_ascii(&red, &green, &blue, "green");
|
||||
test_color_rgb_xy_gamma_unit(red, green, blue, 0.115, 0.826, 40);
|
||||
test_color_rgb_xy_gamma_unit(red, green, blue, 0.115f, 0.826f, 40);
|
||||
color_rgb_from_ascii(&red, &green, &blue, "red");
|
||||
test_color_rgb_xy_gamma_unit(red, green, blue, 0.735, 0.265, 59);
|
||||
test_color_rgb_xy_gamma_unit(red, green, blue, 0.735f, 0.265f, 59);
|
||||
color_rgb_from_ascii(&red, &green, &blue, "maroon");
|
||||
test_color_rgb_xy_gamma_unit(red, green, blue, 0.735, 0.265, 12);
|
||||
test_color_rgb_xy_gamma_unit(red, green, blue, 0.735f, 0.265f, 12);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#if defined(CONFIG_ZTEST_NEW_API)
|
||||
ZTEST(property_tests, testPropList)
|
||||
#else
|
||||
void testPropList(void)
|
||||
static void testPropList(void)
|
||||
#endif
|
||||
{
|
||||
unsigned i = 0, j = 0;
|
||||
|
||||
@@ -217,9 +217,9 @@ static void testWriteProperty(void)
|
||||
testWritePropertyTag(&value);
|
||||
value.type.Real = 1.0;
|
||||
testWritePropertyTag(&value);
|
||||
value.type.Real = 3.14159;
|
||||
value.type.Real = 3.14159f;
|
||||
testWritePropertyTag(&value);
|
||||
value.type.Real = -3.14159;
|
||||
value.type.Real = -3.14159f;
|
||||
testWritePropertyTag(&value);
|
||||
|
||||
value.tag = BACNET_APPLICATION_TAG_ENUMERATED;
|
||||
|
||||
@@ -69,7 +69,7 @@ static void testWritePropertyMultiple(void)
|
||||
property_value[0].propertyIdentifier = PROP_PRESENT_VALUE;
|
||||
property_value[0].propertyArrayIndex = 0;
|
||||
property_value[0].value.tag = BACNET_APPLICATION_TAG_REAL;
|
||||
property_value[0].value.type.Real = 3.14159;
|
||||
property_value[0].value.type.Real = 3.14159f;
|
||||
property_value[0].value.next = NULL;
|
||||
property_value[0].priority = 0;
|
||||
|
||||
@@ -80,7 +80,7 @@ static void testWritePropertyMultiple(void)
|
||||
property_value[1].propertyIdentifier = PROP_PRESENT_VALUE;
|
||||
property_value[1].propertyArrayIndex = 0;
|
||||
property_value[1].value.tag = BACNET_APPLICATION_TAG_REAL;
|
||||
property_value[1].value.type.Real = 1.41421;
|
||||
property_value[1].value.type.Real = 1.41421f;
|
||||
property_value[1].value.next = NULL;
|
||||
property_value[1].priority = 0;
|
||||
|
||||
|
||||
@@ -422,7 +422,7 @@ void z_ztest_run_test_suite(const char *name, struct unit_test *suite)
|
||||
test_status = (test_status || fail) ? 1 : 0;
|
||||
}
|
||||
|
||||
void end_report(void)
|
||||
static void end_report(void)
|
||||
{
|
||||
if (test_status) {
|
||||
TC_END_REPORT(TC_FAIL);
|
||||
|
||||
Reference in New Issue
Block a user