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

Fixed compilation for ESP32 and ESP8266 with -Werror=unused-variable #118

Closed
wants to merge 0 commits into from
Closed

Conversation

matthias-bs
Copy link

I am using OneWire in a larger project of mine (https://github.com/matthias-bs/BresserWeatherSensorTTN). When I added Travis-CI to improve the quality of my own source code, I came across the following problem:

Last command:  $  /home/travis/arduino-cli --format json compile --fqbn esp32:esp32:featheresp32:FlashFreq=80 --warnings all --dry-run /home/travis/Arduino/libraries/OneWire/examples/DS18x20_Temperature/DS18x20_Temperature.ino

/home/travis/Arduino/libraries/OneWire/OneWire.cpp: In member function 'uint8_t OneWire::reset()':

/home/travis/Arduino/libraries/OneWire/OneWire.cpp:169:24: warning: unused variable 'reg' [-Wunused-variable]

  volatile IO_REG_TYPE *reg IO_REG_BASE_ATTR = baseReg;

                        ^~~

/home/travis/Arduino/libraries/OneWire/OneWire.cpp: In member function 'void OneWire::write_bit(uint8_t)':

/home/travis/Arduino/libraries/OneWire/OneWire.cpp:204:24: error: unused variable 'reg' [-Werror=unused-variable]

  volatile IO_REG_TYPE *reg IO_REG_BASE_ATTR = baseReg;

                        ^~~

/home/travis/Arduino/libraries/OneWire/OneWire.cpp: In member function 'uint8_t OneWire::read_bit()':

/home/travis/Arduino/libraries/OneWire/OneWire.cpp:232:24: error: unused variable 'reg' [-Werror=unused-variable]

  volatile IO_REG_TYPE *reg IO_REG_BASE_ATTR = baseReg;

                        ^~~

cc1plus: some warnings being treated as errors

It seams that the variable reg is used in macros on some architectures, but not on ESP32 and ESP8266. The default setting for arduino-ci and other CI implementations based on arduino-cli is to treat unused variables as errors, which breaks my CI test.
There does not seem to be an easy way to treat included libraries in a different way than your own code.

As a workaround, I added #pragma statements to temporarily switch the compiler to treat the unused variable as warning (just for the offending lines).

Another solution would be to declare the variables only for the architectures which need them.

@matthias-bs
Copy link
Author

Logfile:
https://app.travis-ci.com/github/matthias-bs/OneWire/builds/255255423
(I hope this is visible to anyone...)

@matthias-bs
Copy link
Author

Issue #74 seems to propose another solution.

@uzi18
Copy link

uzi18 commented Sep 7, 2022

@matthias-bs just switch to OneWireNg

@matthias-bs
Copy link
Author

@uzi18: Thanks for the proposal! Done!

@mathertel
Copy link

mathertel commented Sep 22, 2022

Is resolved in the master branch by using __attribute__((unused)).

@brentru
Copy link

brentru commented Oct 12, 2022

@PaulStoffregen #120 seems to do the same thing as this PR proposes. Would it be possible for you or another maintainer to cut a release from master and close out this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants