arduino-cli icon indicating copy to clipboard operation
arduino-cli copied to clipboard

Compiler warnings not shown on subsequent compilations

Open rkost opened this issue 9 years ago • 3 comments
trafficstars

Describe the problem

Compiler warnings for code from non-.ino source files are not shown on subsequent sketch compilations.

To reproduce

When someone writes code like this (see below) he will correctly get two identical warnings:

warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

When one compiles it again the warnings will all disappear so the user (me) thinks he is perfectly fine and writing clean code.

FunFact: This will not happen if all code is written to the main (.ino) file.

File DummyClass.h:

class DummyClass
{
public:
  char* getString();

  char* getSecondString();
};

File DummyClass.cpp:

char* DummyClass::getString()
{
  return "Some String";
}

char* DummyClass::getSecondString()
{
  return "Some other string";
}

File test.ino:

#include "DummyClass.h"
DummyClass dummy;

void setup()
{
  Serial.begin(115200);
}
void loop()
{
  Serial.println(dummy.getString());
  delay(1000);
}

Expected behavior

Compiler warnings are shown every time the sketch is compiled if the code would produce a warning.

Arduino CLI version

60a8aa96c725d0ebce9bbe4586013908669f14ff

Operating system

All

Operating system version

Any

Additional context

Additional reports

  • https://forum.arduino.cc/t/arduino-ide-2-0-3-duplicate-tab-page/1084561/5
  • https://forum.arduino.cc/t/warning-disappears-after-second-compilation/1139615
  • https://forum.arduino.cc/t/bad-behaviour-using-keypad/1231737/9
  • https://forum.arduino.cc/t/feature-request-clean-build-option/1291789/9

Related

  • https://github.com/arduino/arduino-cli/issues/2204

Issue checklist

  • [X] I searched for previous reports in the issue tracker
  • [X] I verified the problem still occurs when using the nightly build
  • [X] My report contains all necessary details

rkost avatar Oct 15 '16 23:10 rkost

This is caused by caching: the second time the file is not recompiled if it was unchanged, so the warnings are not shown. The only way I can see to fix this (other than making warnings into errors), is to cache the stdout/stderr output as well, so it can be shown again even when not running the compiler. Not sure if this is the best way to approach this, though.

matthijskooijman avatar Oct 17 '16 13:10 matthijskooijman

@matthijskooijman is correct, caching elides warnings from previous compilations. I believe that ccache caches stdout/stderr and replays them even if the cached version is unchanged, so the approach could be ok, we only need to find a suitable "backend" for storing this information (taking care it also works in a cloud infrastructure)

facchinm avatar Oct 20 '16 13:10 facchinm

There is some valuable related discussion here: https://github.com/arduino/arduino-builder/pull/301

Matthijs was kind enough to add a link to here on that end, but it seems the backtrack reference generated by GitHub was lost when I transferred this issue from the arduino/Arduino repo.

per1234 avatar Jun 19 '21 02:06 per1234