Compiler warnings treated as errors on gcc 6.2
user115122 opened this issue · comments
When building the example on ubuntu 16.10, gcc 6.2.0, there are warnings treated as errors:
$ make example
[ 12%] Building C object CMakeFiles/lwmqtt.dir/src/client.c.o
In file included from /usr/include/stdint.h:25:0,
from /usr/lib/gcc/i686-linux-gnu/6/include/stdint.h:9,
from /home/user/src/lwmqtt/include/lwmqtt.h:6,
from /home/user/src/lwmqtt/src/helpers.h:4,
from /home/user/src/lwmqtt/src/packet.h:4,
from /home/user/src/lwmqtt/src/client.c:1:
/usr/include/features.h:148:3: error: #warning "_BSD_SOURCE and _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE" [-Werror=cpp]
# warning "_BSD_SOURCE and _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE"
^~~~~~~
cc1: all warnings being treated as errors
CMakeFiles/lwmqtt.dir/build.make:62: recipe for target 'CMakeFiles/lwmqtt.dir/src/client.c.o' failed
Ignoring that one with -Wno-error=cpp reveals the next one:
/home/user/src/lwmqtt/src/helpers.c: In function ‘lwmqtt_read_bits’:
/home/user/src/lwmqtt/src/helpers.c:6:22: error: left shift of negative value [-Werror=shift-negative-value]
int mask = (~((~0) << num)) << pos;
^~
/home/user/src/lwmqtt/src/helpers.c: In function ‘lwmqtt_write_bits’:
/home/user/src/lwmqtt/src/helpers.c:11:22: error: left shift of negative value [-Werror=shift-negative-value]
int mask = (~((~0) << num)) << pos;
^~
cc1: all warnings being treated as errors
CMakeFiles/lwmqtt.dir/build.make:86: recipe for target 'CMakeFiles/lwmqtt.dir/src/helpers.c.o' failed
Ignoring that one reveals the third one:
/home/user/src/lwmqtt/src/packet.c: In function ‘lwmqtt_decode_publish’:
/home/user/src/lwmqtt/src/packet.c:440:25: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
if (buf_end - buf_ptr < rem_len) {
^
I wonder where the issue comes from... The project compiles fine on my machine (osx), travis (ubuntu 14.04.5, gcc 4.8.4) with the Arduino IDE and the esp-idf. AFAIK all use -Wall -Wextra -Wpedantic -Werror
and such.
Either the new version of gcc is much more restrictive or there is somewhere a misconfiguration.
Can you post all the commands and files needed to reconstruct this situtation on a pristine Ubuntu 16.10 VM?
Also, did you modify lwmqtt
in some way before running cmake
and make example
?
It compiles fine on my OSX machine as well, and I'm surprised clang doesn't complain. Oh well.
There are no modifications to lwmqtt before building.
It's just a standard install of ubuntu, nothing fancy. sudo apt-get install gcc cmake git ; git clone https://github.com/256dpi/lwmqtt.git && cd lwmqtt && cmake . && make example
I'm too constrained on time right now to set up a new VM, but if it's REALLY needed I might eventually get it done some day, but don't hold your breath. I think your right, the new gcc is a lot more picky. Some of those warning options weren't even available in older versions of gcc if I remember correctly.
The last problem referenced in this issue is easy to fix, and the first problem I've seen others fix like so:
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6810db1..1f76a0a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -8,7 +8,7 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wpedantic -Werror -Wno-unused
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -Werror -Wno-unused-parameter")
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c1x -D_POSIX_C_SOURCE=200112L -D_BSD_SOURCE")
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c1x -D_POSIX_C_SOURCE=200112L -D_DEFAULT_SOURCE -D_GNU_SOURCE")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11")
The second problem, well, I haven't thoroughly analyzed what you do in your bithelpers, so I don't have any suggestion there.
I fixed the bit helpers to build without errors on a recent Ubuntu VM with gcc 7.2.0. Your project should compile now as well.
Yes, very nice!
That fixes all but the last problem:
/home/user/src/lwmqtt/src/packet.c: In function 'lwmqtt_decode_publish':
/home/user/src/lwmqtt/src/packet.c:440:25: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
if (buf_end - buf_ptr < rem_len) {
^
cc1: all warnings being treated as errors
Ok, I updated the master branch. Can you confirm the fix?
Fix confirmed. Thank you very much, good Sir!