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

Including FastLED library breaks prototype generation

Open per1234 opened this issue 8 years ago • 3 comments

Using Arduino IDE Beta build 25 with Windows 7 64 bit

  • Install FastLED library (it's in the Library Manager index)
  • Compile the following sketch (EDIT: for Arduino/Genuino Uno or other AVR board):
#include <FastLED.h>
void setup() {
  foo();
}
void loop() {}
void foo() {}

Error:

C:\Users\per\AppData\Local\Temp\arduino_modified_sketch_198423\sketch_nov21a.ino: In function 'void setup()':

sketch_nov21a:5: error: 'foo' was not declared in this scope

 void loop() {}

       ^

arduino-preprocessor -debug output: https://gist.githubusercontent.com/per1234/e2e45e7b84de756ae1782178790c5830/raw/ecdd542f40c951ca8b93f9a585ee72366f6fcfaa/sketch_nov21a.ino.cpp

Examination of the generated .ino.cpp file shows that the foo() prototype was never generated, rather than being inserted in the wrong place.

The issue does not occur in Arduino IDE 1.8.5.

Originally reported at: http://forum.arduino.cc/index.php?topic=512898

per1234 avatar Nov 22 '17 02:11 per1234

Hi @per1234 , thanks for spotting this; in fact, the libclang backend is failing to analyze a part of the library (it looks like it's the AVR specific macros, incidentally the ones making FastLed magic happen ) and thus it doesn't generate the prototypes. I can think about a couple of solutions (maybe @cmaglie has some other):

  • fallback on ctags when arduino-preprocessor fails (at least, in the meantime, just to avoid breaking people's sketches)
  • only use user program to generate the prototypes (this should work for prototype generation if no gcc-specific macro is used, but won't provide autocomplete hints)

Anyway, comping on ARM works as expected, so we can use it as a reference. The error thrown (with --output-diagnostic) is

terminate called after throwing an instance of 'std::logic_error'
  what():  basic_string::_S_construct null not valid
Aborted (core dumped)

facchinm avatar Nov 27 '17 09:11 facchinm

in fact solve it with this code block

#include <FastLED.h>
void foo();
void setup() {
  foo();
}
void loop() {}
void foo() {}

LEKPHET-KUNSUE avatar Jan 27 '24 07:01 LEKPHET-KUNSUE

try it.

LEKPHET-KUNSUE avatar Jan 27 '24 07:01 LEKPHET-KUNSUE