PaulStoffregen / OneWire

Library for Dallas/Maxim 1-Wire Chips
http://www.pjrc.com/teensy/td_libs_OneWire.html
579 stars 382 forks source link

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

Closed matthias-bs closed 8 months ago

matthias-bs commented 1 year ago

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 commented 1 year ago

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

matthias-bs commented 1 year ago

Issue https://github.com/PaulStoffregen/OneWire/issues/74 seems to propose another solution.

uzi18 commented 1 year ago

@matthias-bs just switch to OneWireNg

matthias-bs commented 1 year ago

@uzi18: Thanks for the proposal! Done!

mathertel commented 1 year ago

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

brentru commented 1 year ago

@PaulStoffregen https://github.com/PaulStoffregen/OneWire/pull/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?