Skip to content

Non-class function prototypes are sometimes inserted inside class definition. #292

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
oqibidipo opened this issue Sep 15, 2018 · 5 comments · Fixed by #294
Closed

Non-class function prototypes are sometimes inserted inside class definition. #292

oqibidipo opened this issue Sep 15, 2018 · 5 comments · Fixed by #294
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

@oqibidipo
Copy link

A.k.a. "Hello class, I found by the road some functions that look a bit like what we alrady have. Let's throw them in."

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

Example code

class Foo {
    int blooper(int x) { return x+1; }
};

Foo foo;

void setup() {
  foo.setup();
}

void loop() {
  foo.loop();
}

With generated prototypes

#include <Arduino.h>
#line 1 "/Users/rjl/Documents/Arduino/bug_proto_1/bug_proto_1.ino"
#line 1 "/Users/rjl/Documents/Arduino/bug_proto_1/bug_proto_1.ino"
class Foo {
#line 7 "/Users/rjl/Documents/Arduino/bug_proto_1/bug_proto_1.ino"
void setup();
#line 11 "/Users/rjl/Documents/Arduino/bug_proto_1/bug_proto_1.ino"
void loop();
#line 2 "/Users/rjl/Documents/Arduino/bug_proto_1/bug_proto_1.ino"
    int blooper(int x) { return x+1; }
};

Foo foo;

void setup() {
  foo.setup();
}

void loop() {
  foo.loop();
}

This happens when the name of a function is the same as or a substring of a name of class method like loop is a substring of blooper in the example.

Tested with IDE version 1.8.7, Mac OS X 10.11.6.
OK with 1.8.5.

@oqibidipo
Copy link
Author

These produce different errors depending on the situation:

void setup() {
  foo.setup();
}

void loop() {
  foo.loop();
}

Correct result:

error: 'class Foo' has no member named 'setup'
error: 'class Foo' has no member named 'loop'

Buggy result:

error: 'void Foo::setup()' is private
error: 'void Foo::loop()' is private

@facchinm facchinm added the bug label Sep 17, 2018
@facchinm
Copy link
Member

The bug is caused by 287a9c8#diff-d9628c6c5e4ac5689a2cee322bf97ad5R73 ; I'm checking if there's a more clever way to check for matching signatures

facchinm added a commit to facchinm/arduino-builder that referenced this issue Sep 17, 2018
@facchinm
Copy link
Member

@oqibidipo would you mind testing #294 ? Thanks!

@oqibidipo
Copy link
Author

Seems to do the right thing with my example.

#include <Arduino.h>
#line 1 "/Users/rjl/Documents/Arduino/bug_proto_1/bug_proto_1.ino"
#line 1 "/Users/rjl/Documents/Arduino/bug_proto_1/bug_proto_1.ino"
class Foo {
    int blooper(int x) { return x+1; }
};

Foo foo;

#line 7 "/Users/rjl/Documents/Arduino/bug_proto_1/bug_proto_1.ino"
void setup();
#line 11 "/Users/rjl/Documents/Arduino/bug_proto_1/bug_proto_1.ino"
void loop();
#line 7 "/Users/rjl/Documents/Arduino/bug_proto_1/bug_proto_1.ino"
void setup() {
  foo.setup();
}

void loop() {
  foo.loop();
}

Compilation fails with the 'correct' errors:

/Users/rjl/Documents/Arduino/bug_proto_1/bug_proto_1.ino: In function 'void setup()':
bug_proto_1:8:7: error: 'class Foo' has no member named 'setup'
   foo.setup();
       ^
/Users/rjl/Documents/Arduino/bug_proto_1/bug_proto_1.ino: In function 'void loop()':
bug_proto_1:12:7: error: 'class Foo' has no member named 'loop'
   foo.loop();
       ^

@domenpk
Copy link

domenpk commented Sep 17, 2018

FWIW #294 fixes my issue.

@rsora rsora added the type: imperfection Perceived defect in any part of project label Sep 22, 2021
@per1234 per1234 added conclusion: resolved Issue was resolved topic: code Related to content of the project itself topic: preprocessor Related to sketch preprocessing labels Oct 13, 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.

5 participants