Eralt / arduino

Automatically exported from code.google.com/p/arduino
0 stars 0 forks source link

Prototypes for methods with default arguments are not generated #386

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Steps to reproduce the issue:

STEP 1. Insert the following code into a blank sketch:

void setup() {
  test(42);
  test2(42);
}

void loop() {}
void test(int arg) {};
void test2(int arg = 0) {};

STEP 2: Click the verify button and observe the error message:

DefaultArgBugDemo.cpp: In function 'void setup()':
DefaultArgBugDemo:2: error: 'test2' was not declared in this scope

STEP 3:
Examine the generated *.cpp file and observe that a prototype has been 
generated for test1 but not test2:

#include "WProgram.h"
void setup();
void loop();
void test(int arg);
void setup() {
  test(42);
  test2(42);
}

void loop() {}
void test(int arg) {};
void test2(int arg = 0) {};

What is the expected output? What do you see instead?

You would expect a prototype to be generated for test2.

What version of the Arduino software are you using? On what operating
system?  Which Arduino board are you using?

Tested in 0018 and 0021. Running on Win7 Home Premium (though the issue likely 
exists on all platforms)

Please provide any additional information below.

Of course the workaround is relatively simple (just define the prototype 
yourself) but it would be nice for all methods to be treated equally.

Original issue reported on code.google.com by andre...@gmail.com on 23 Oct 2010 at 1:23

GoogleCodeExporter commented 9 years ago
Just realised the unnecessary semicolons at the end of the function 
definitions, removing the semicolons does not affect the existence of the bug.  

Original comment by andre...@gmail.com on 23 Oct 2010 at 1:29

GoogleCodeExporter commented 9 years ago
Currently your own prototype will be superseded by the auto generated one. This 
patch 
https://github.com/EbiDK/Arduino/commit/96fc3c18c0cb118ec273947590e27114bfd7970d
 fixes that.

Still, that doesn't fix this issue, but the two regular expressions in the 
patch(one in the current code) seem to be the right place to fix this, I'm not 
good enough at regular expressions to try to fix it though. I'm worried I'd 
break some other case it should be matching.

Original comment by lars.j.n...@gmail.com on 3 Mar 2012 at 7:06

GoogleCodeExporter commented 9 years ago
See issue 973 for a workaround.  

Original comment by dmel...@gmail.com on 31 Jul 2012 at 12:46

GoogleCodeExporter commented 9 years ago
Please checkout this thread [1] on devs mailing list and try one of the linked 
IDEs. It should fix the problems reported in this issue
[1] https://groups.google.com/a/arduino.cc/forum/#!topic/developers/4X2T3rCxXWM

Original comment by federico...@gmail.com on 21 Jan 2015 at 10:06

GoogleCodeExporter commented 9 years ago
New preprocessor tracked at https://github.com/arduino/Arduino/pull/2636. 
Builds for testing it are available

Original comment by federico...@gmail.com on 13 Feb 2015 at 7:19