Open jfjlaros opened 2 years ago
Thanks for your report @jfjlaros.
You can see the problem in the program produced after Arduino sketch preprocessing:
$ arduino-cli version
arduino-cli.exe Version: git-snapshot Commit: 4a4b784c Date: 2022-06-26T23:40:19Z
$ SKETCH_PATH="/tmp/SlashBug"
$ mkdir "$SKETCH_PATH"
$ printf "template <size_t N>\nvoid test(size_t arr[N / 2]) {}\nvoid setup() {}\nvoid loop() {}\n" > "$SKETCH_PATH"/SlashBug.ino
$ arduino-cli compile --fqbn arduino:avr:uno --preprocess "$SKETCH_PATH"
#include <Arduino.h>
#line 0 "C:\\Users\\per\\AppData\\Local\\Temp\\SlashBug\\SlashBug.ino"
template <size_t N>void test(size_t arr[N \/ 2]);
#line 3 "C:\\Users\\per\\AppData\\Local\\Temp\\SlashBug\\SlashBug.ino"
void setup();
#line 4 "C:\\Users\\per\\AppData\\Local\\Temp\\SlashBug\\SlashBug.ino"
void loop();
#line 0 "C:\\Users\\per\\AppData\\Local\\Temp\\SlashBug\\SlashBug.ino"
#line 1 "C:\\Users\\per\\AppData\\Local\\Temp\\SlashBug\\SlashBug.ino"
template <size_t N>
void test(size_t arr[N / 2]) {}
void setup() {}
void loop() {}
Note the backslash that was inserted into the generated prototype:
template <size_t N>void test(size_t arr[N \/ 2]);
@per1234 done :wink:
@jfjlaros it's indeed a nasty bug, mostly due to the fact that ctags
is not very template friendly, so we had to create special cases and probably multiline is not well tested. Thanks for the PoC btw
Here is an other one. The following function definition
template <size_t N>
void func(double const (&)[N]) {}
gives rise to these errors (different than the ones in the previous example)
arduino-cli compile --fqbn arduino:avr:pro --warnings all --output-dir build \
--build-property compiler.cpp.extra_flags="-pedantic"
.../x.ino:3:45: error: variable or field 'func' declared void
.../x.ino:3:30: error: expected primary-expression before 'double'
while
template <size_t N> void func(double const (&)[N]) {}
compiles fine.
Describe the problem
When trying to compile the following sketch,
this error is raised:
When the function definition is changed as follows, everything works fine.
This issue seems to be independent of which core is used (tried AVR and ESP) and of which platform is used (tried Linux and Wokwi simulator).
Arduino CLI version
4a4b784c
Operating system
Operating system version
Additional context
For reference, the following program compiles without errors or warnings
with the following command:
Issue checklist