Prototype incorrectly generated for struct member function under certain conditions #2161
Open
3 tasks done
Labels
topic: build-process
Related to the sketch build process
type: imperfection
Perceived defect in any part of project
Prototype incorrectly generated for struct member function under certain conditions
Describe the problem
In order to make it easier for beginners to get started with writing Arduino sketches, and for the convenience of all users, Arduino CLI automatically generates and adds prototypes for functions defined in a
.ino
file of a sketch.Under certain specific conditions, a prototype is incorrectly generated for
struct
member functions:enum
is declared above the function.enum
has an "enum-base" (e.g.,enum bar_t : int
).enum
contains a comma (either a trailing comma on a single identifier (e.g.,{pippo,}
) or separating multiple identifiers (e.g.,{pippo, pluto}
).🐛 The prototype causes a spurious compilation failure of what would otherwise be valid code.
To reproduce
Setup environment
Demo
🐛 There was a spurious compilation failure of valid code.
By looking at the C++ code generated by the Arduino sketch preprocessor, we can see the cause of the error:
🐛 The spurious compilation failure was caused by Arduino CLI creating a prototype for the
baz
function.🐛 Prototypes for the
setup
andloop
functions were not generated as expected.Expected behavior
Prototype generation should always be skipped for struct member functions.
Arduino CLI version
Original report
0b77c0a
Last verified with
c5812ee
Operating system
Operating system version
Additional context
The behavior is as expected when the sketch code doesn't have the specific conditions described above. For example, this sketch compiles without any error because a function prototype is not generated for
baz
:Preprocessed sketch:
Related
extern "C"
when comment contains//
#1591extern "C"
when usingextern "C" { ... }
to mix C functions in an.ino
file. #1618Workaround
Put the
struct
in a.h
file. Only.ino
files undergo Arduino sketch preprocessing so doing this will avoid the incorrect function prototype generation.Issue checklist
The text was updated successfully, but these errors were encountered: