Skip to content

Auto generated function declarations no longer works for callbacks assigned at variable declaration #180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
AlexanderBrevig opened this issue Sep 28, 2016 · 3 comments
Labels
conclusion: resolved Issue was resolved topic: code Related to content of the project itself topic: preprocessor Related to sketch preprocessing type: imperfection Perceived defect in any part of project

Comments

@AlexanderBrevig
Copy link

AlexanderBrevig commented Sep 28, 2016

Here's and example that will break the auto generation of function declarations in the IDE, not sure for how long but I've gotten regular support request for a good while now.
The only thing I know, this used to work.

// say you have a library that accepts a callback
class BUG {public:BUG(void (*fn)(void)){}};

//void makeItBreak(){} //uncomment to fix
BUG b(makeItBreak); //this will break

void setup(){}
void loop(){}
void makeItBreak(){}
@facchinm
Copy link
Member

facchinm commented Dec 6, 2016

Hi @AlexanderBrevig,
#191 contains a fix for this, however I'm not entirely happy about that patch (too much guesswork). If you change your code in the (semantically equivalent)

class BUG {public:BUG(void (*fn)(void)){}};

BUG b(&makeItBreak); //this will not break

void setup(){}
void loop(){}
void makeItBreak(){}

it works correctly with released builder.
Do you think it can be an acceptable solution?

@AlexanderBrevig
Copy link
Author

It is an improvement but does not help in that it still is not 'backward compatible'. If I have to choose explaining moving a function above it, and adding the & I'll go for the former.

I'd personally still like this to be included though :) personally it's a win! Sadly though, not for the target audience.

facchinm added a commit to facchinm/arduino-builder that referenced this issue Jan 20, 2017
Fixes arduino#206

The sample code from the issue provided a smart way to cheat the dumb FP parser.
In fact, the & is referred to the return type (correct) but the comparator doesn't know about semantics and simply prepends the ampersand before searching for the match.
So the code matches itself, which makes absolutely no sense.
Avoiding this occurrence fixes the issue, however the entire code for prototype line insertion should be refactored in a saner way (see arduino#180 and arduino#191 for another problem)
facchinm added a commit to facchinm/arduino-builder that referenced this issue Mar 17, 2017
facchinm added a commit to facchinm/arduino-builder that referenced this issue Mar 17, 2017
facchinm added a commit to facchinm/arduino-builder that referenced this issue Mar 17, 2017
@facchinm
Copy link
Member

Fixed by 3282535

@per1234 per1234 added conclusion: resolved Issue was resolved topic: code Related to content of the project itself topic: preprocessor Related to sketch preprocessing type: imperfection Perceived defect in any part of project labels Oct 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conclusion: resolved Issue was resolved topic: code Related to content of the project itself topic: preprocessor Related to sketch preprocessing type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants