Skip to content
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

Incorrect placement of auto-generated prototypes gives misleading error messages #362

Open
6v6gt-duino opened this issue Nov 1, 2020 · 4 comments
Labels
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

@6v6gt-duino
Copy link

6v6gt-duino commented Nov 1, 2020

This issue is also mentioned here: https://forum.arduino.cc/index.php?topic=711626.0 (post #7)

The expected behaviour is that this simple code example should compile:

// Arduino IDE 1.8.13

enum class StateA { one, two, three } ;
StateA stateA ;

void setStateA( StateA newState ) {
  stateA = newState ;
}

enum class StateB { one, two, three } ;
StateB stateB ;

void setStateB( StateB newState ) {
  stateB = newState ;
}

void setup() {
  // put your setup code here, to run once:
  Serial.begin( 115200 ) ;
  setStateA( StateA::one ) ;
  setStateB( StateB::one ) ;
}

void loop() {
}

The observed behaviour is this:

sketch_oct10a:11:17: error: variable or field 'setStateB' declared void
 void setStateB( StateB newState ) {
                 ^~~~~~
sketch_oct10a:11:17: error: 'StateB' was not declared in this scope
C:\Users\6V6GT\Documents\Arduino\sketch_oct10a\sketch_oct10a.ino:11:17: note: suggested alternative: 'StateA'
 void setStateB( StateB newState ) {
                 ^~~~~~
                 StateA
exit status 1
variable or field 'setStateB' declared void

The reason is clearly that one auto-generated function prototype has been wrongly placed (from the file ino.cpp ):

#include <Arduino.h>
#line 1 "C:\\Users\\6V6GT\\Documents\\Arduino\\sketch_oct10a\\sketch_oct10a.ino"
enum class StateA { one, two, three } ;
StateA stateA ;

#line 4 "C:\\Users\\6V6GT\\Documents\\Arduino\\sketch_oct10a\\sketch_oct10a.ino"
void setStateA( StateA newState );
#line 11 "C:\\Users\\6V6GT\\Documents\\Arduino\\sketch_oct10a\\sketch_oct10a.ino"
void setStateB( StateB newState );
#line 15 "C:\\Users\\6V6GT\\Documents\\Arduino\\sketch_oct10a\\sketch_oct10a.ino"
void setup();
#line 22 "C:\\Users\\6V6GT\\Documents\\Arduino\\sketch_oct10a\\sketch_oct10a.ino"
void loop();
#line 4 "C:\\Users\\6V6GT\\Documents\\Arduino\\sketch_oct10a\\sketch_oct10a.ino"
void setStateA( StateA newState ) {
  stateA = newState ;
}

enum class StateB { one, two, three } ;
StateB stateB ;

void setStateB( StateB newState ) {
  stateB = newState ;
}

void setup() {
  // put your setup code here, to run once:
  Serial.begin( 115200 ) ;
  setStateA( StateA::one ) ;
  setStateB( StateB::one ) ;
}

void loop() {
}
@facchinm
Copy link
Member

facchinm commented Nov 2, 2020

Hi @6v6gt-duino ,
thank for reporting! The issue lies in the prototype generator as you noticed. What bothers me is that both functions are already declared before their usage so the prototype generator shouldn't create anything.
We'll investigate soon and report back

@6v6gt-duino
Copy link
Author

6v6gt-duino commented Dec 17, 2020

Here is another link including a discussion of this issue and including additional error/test cases: https://forum.arduino.cc/index.php?topic=718515.0

@per1234 per1234 added 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 Sep 30, 2021
@sterretjeToo
Copy link

This topic is now nearly 3 years old. The problem persists in IDE 2.1.1.

We'll investigate soon and report back

A concerned Arduino user ;)

@6v6gt-duino
Copy link
Author

That gives me the opportunity of adding another example which has occurred in the meantime: https://forum.arduino.cc/t/is-the-location-of-a-global-function-important/996378

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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

No branches or pull requests

4 participants