autolab / Autolab-CLI

Command line autolab client that uses the Autolab API
3 stars 2 forks source link

using GCC 7.3.0, build fails on minor compiler warning (parentheses) #15

Closed mtoupsUNO closed 2 years ago

mtoupsUNO commented 5 years ago
/tmp/autolab-cli/src/file/file_utils.cpp:118:17: error: suggest parentheses around assignment used as truth value [-Werror=parentheses]
   while (amount = TEMP_FAILURE_RETRY(read(fd, result + total_read, max_length))) {
                 ^
cc1plus: all warnings being treated as errors

This does not occur in older versions of GCC, so I assume that's why this wasn't caught sooner.

It seems a little silly, but simply adding another pair of parentheses around that while condition will satisfy GCC. I found that a bit distasteful, so instead I added -Wno-error=parentheses to CMakeLists.txt on this line:

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra -Werror -Wno-error=parentheses")

At least one of these changes should be made, or else the client won't compile on recent versions of GCC.

fanpu commented 5 years ago

Dear @mtoupsUNO , thanks for bringing this to our attention and investigating it. May I know which version of GCC this error is raised on?

mtoupsUNO commented 5 years ago

I was building the client using:

gcc version 7.3.0 (Ubuntu 7.3.0-27ubuntu1~18.04)

This is the version of gcc that ships with Ubuntu 18.04 LTS, so it is common and will only become more widespread as older Linux systems are updated.

The same warning/error does occur on Ubuntu 17.10 using gcc version 7.2.0 (Ubuntu 7.2.0-8ubuntu3.2)

The same warning/error does not occur in gcc version 6.3.0. Presumably any gcc version before that is also fine.

It appears that GCC's warnings about parentheses got stricter sometime during 2017.

TheodorJ commented 5 years ago

I think the best solution to this is to add parentheses to the existing code. In the future, if we make an error in the code where we write "=" instead of "==", it would be helpful to have this error.