Compile errors by .ino into .cpp expansion when using macro's and namespaces

Hi

I have encountered a problem with the way the Arduino IDE expands its .ino file into a .cpp file (temp folder). It basically includes the arduino.h and tries to forward declare the methods you have in the .ino.

Here's such an expansion for an empty sketch.

#line 1 "MyProject.ino"
#include "Arduino.h"
void setup();
void loop();
#line 14
void setup() {
                                           
}

void loop() {

}

I have found two scenario's where this breaks down and causes compile errors (syntax).

  1. When I have a function in my sketch that returns a type that is declared in a namespace. The extra code is inserted before the 'using namespace MyNamespace' - so the forward declaration uses a (return) type that can not be located. Also fully qualifying the type does not work for the namespace info is not copied to the forward decls.

  2. Using a macro in a function declaration copies over the macro. I have some macros that declare a method. Two macro's are used a 'begin' (method name and opening bracket) and an 'end' macro (closing bracket). The 'end' macro (but not the begin macro) is also copied to the forward decls resulting in a syntax error.

So clearly some more intelligence must go into retrieving the forward decls information... :slight_smile:

Hope it helps,
Marc

Running:
Arduino IDE 1.6.5
Windows 8.1

I think that if you put in your own forward declarations the IDE does not insert its own for you. That should work for case 1. I don't know if it works for case 2.