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

Error on building : "HttpClient.cpp:87:61: error: logical not is only applied to the left hand side of comparison [-Werror=logical-not-parentheses] if (!iClient->connect(iServerName, iServerPort) > 0)" #97

Open
genotix opened this issue Jan 20, 2021 · 2 comments
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project

Comments

@genotix
Copy link

genotix commented Jan 20, 2021

There is this Mobile library TinyGSM that uses that ArduinoHttpClient library for an HTTPS example.
I have been working to try and do a HTTPS PUT with the TTGO T-Call v1.4 ; an ESP32 WROVER-B with a SIM800L GPRS module.

I have tried this https://github.com/vshymanskyy/TinyGSM/blob/master/examples/HttpsClient/HttpsClient.ino but immediately receive the following error in Arduino IDE:

Warning: Board breadboard:avr:atmega328bb doesn't define a 'build.board' preference. Auto-set to: AVR_ATMEGA328BB
/Users/genotix/Documents/Arduino/libraries/ArduinoHttpClient-0.4.0/src/HttpClient.cpp: In member function 'int HttpClient::startRequest(const char*, const char*, const char*, int, const byte*)':
/Users/genotix/Documents/Arduino/libraries/ArduinoHttpClient-0.4.0/src/HttpClient.cpp:87:61: error: logical not is only applied to the left hand side of comparison [-Werror=logical-not-parentheses]
             if (!iClient->connect(iServerName, iServerPort) > 0)
                                                             ^
/Users/genotix/Documents/Arduino/libraries/ArduinoHttpClient-0.4.0/src/HttpClient.cpp:97:64: error: logical not is only applied to the left hand side of comparison [-Werror=logical-not-parentheses]
             if (!iClient->connect(iServerAddress, iServerPort) > 0)
                                                                ^
cc1plus: some warnings being treated as errors
exit status 1
Error compiling for board ESP32 Dev Module.

Since it is the demo example I am wondering what could be in err here.
Would appreciate any hints. :) 👍

@per1234
Copy link

per1234 commented Jan 20, 2021

The ESP32 platform authors used an innovative approach to advocating for warning-free code:
https://github.com/espressif/arduino-esp32/blob/1.0.4/platform.txt#L18-L21

compiler.warning_flags.none=-w
compiler.warning_flags.default=
compiler.warning_flags.more=-Wall -Werror=all
compiler.warning_flags.all=-Wall -Werror=all -Wextra

What this does is add the -Werror=all flag to the compilation command when you have the Arduino IDE's File > Preferences > Compiler warnings set to "More" or "All". The -Werror=all flag causes compiler warnings to be upgraded to errors.

You can see this is the cause of the error you got:

some warnings being treated as errors

Of course, the solution is to fix the library code that is causing the warning. But if you need a provisional workaround you can set the Arduino IDE's File > Preferences > Compiler warnings to "Default" when compiling sketches that use this library. Since the extra warnings you get from the "More" or "All" settings can be very useful, I recommend changing your compiler warnings setting to the higher level when you are working with clean code that doesn't generate warnings under normal conditions.

@per1234 per1234 added the type: imperfection Perceived defect in any part of project label Jan 20, 2021
@genotix
Copy link
Author

genotix commented Jan 21, 2021

Thank you very much for this clear explanation!
I have been able to change it and could continue!

@per1234 per1234 added the topic: code Related to content of the project itself label Aug 5, 2023
@per1234 per1234 linked a pull request Aug 5, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants