Description
1. C++11 trailing return types.
void setup(){
func();
}
void loop() {}
auto func() -> void{
}
This problem isn't really a big issue, a user can simply add a prototype or define above the code where it is called from (preprocessor ignores completely). Its the next problems which cause quite a disaster.
2. Returning a function pointer.
void setup(){
func()();
}
void loop(){}
void (*func())(){
return setup;
}
This causes a complete failure as the prototype is generated wrong. As the generated prototype differs only by return type, the function is ambiguous and the compiler cannot continue.
#line 1
#line 1 "C:\\Users\\Chris\\AppData\\Local\\Temp\\arduino_cdba69ab332f1f472a84ede0e3d7b376\\sketch_oct08c.ino"
void setup();
void loop();
void func();
#line 1
void setup(){
func()();
}
void loop(){}
void (*func())(){
return setup;
}
3. Returning an array reference.
int array[5];
void setup(){
func();
}
void loop(){}
int (&func())[5]{
return array;
}
Just like problem 2, the function prototype is incorrectly generated.
#include <Arduino.h>
#line 1
#line 1 "C:\\Users\\Chris\\AppData\\Local\\Temp\\arduino_55ab6e1d0319f8e5a301e3286e28d726\\sketch_oct08d.ino"
int array[5];
void setup();
void loop();
int func();
#line 4
void setup(){
func();
}
void loop(){}
int (&func())[5]{
return array;
}
4. Combining 2 & 3
Here is a function which accepts and returns: A reference to an array of function pointers which take and int
as a parameter and return nothing.
Bare with me, I know the example below is a little abnormal, its the preprocessor that is interesting.
void setup() {
void (*arr[5])(int);
func(arr);
}
void loop() {}
void (*(&func(void (*(&in)[5])(int)))[5])(int){
return in;
}
And the resulting cpp:
#include <Arduino.h>
#line 1
#line 1 "C:\\Users\\Chris\\AppData\\Local\\Temp\\arduino_b86f1f9b94d497bb6d338315715b6c94\\sketch_oct08a.ino"
void setup();
void loop();
void func(void (*(&in)[5])(int));
#line 1
void setup() {
void (*arr[5])(int);
func(arr);
}
void loop() {}
void (*(&func(void (*(&in)[5])(int)))[5])(int){
return in;
}
As you can see, the preprocessor has correctly copied the functions parameter, but completely removed the return type (apart from the void
).
If you need help, point me in the right direction and I can 'go' have a bit of an investigation.
Or is this a problem within the ctags repo?
I'm just having fun breaking things, I'm sure I'll have a few more additions to my list in the future.