Puzzling #error behavior in nested #if #elif.. What am I doing wrong?

I am in the process of porting the due_can library to support AVR CPUs with built in CAN capability (e.g., ATmega32M1) and have ran into a puzzling issue - perhaps someone can see quickly what I am doing wrong?

At compile time I wish to ID the targeted CPU and set a few variables - example the number of CAN mailboxes. Here is a code snippet:

#if defined(__AVR_AT90CAN32__) || \
    defined(__AVR_AT90CAN64__) || \
    defined(__AVR_AT90CAN128__)
        #define  CANMB_QUANTITY     15                      

#elif defined(__AVR_ATmega32C1__) || \
      defined(__AVR_ATmega64C1__) || \
      defined(__AVR_ATmega16M1__) || \
      defined(__AVR_ATmega32M1__) || \
      defined(__AVR_ATmega64M1__) 
        #define  CANMB_QUANTITY     6                       

#else
 //        #error Unsupported CPU in avr_can.h
#endif 


void setup() {
  Serial.begin(115200);
  
  Serial.println(CANMB_QUANTITY);
  
}

void loop() {

}

When compiling on at ATmega64M1, I get the expected results: 6 so it seems the actual #if Def statements are doing their job.

However, if I un-comment the line: // #error Unsupported CPU in avr_can.h
I get a compiler error - it is almost as if the compiler is picking up the #error, even though it is in an area which should not be resolved...

This problem stated happening when I upgraded to Arduino IDE 1.6.7. If I go back to 1.6.0, the above code fragment works correctly even with the #error line left un-comment.

I do not know is this is perhaps a bug in the latest release, or if the above code fragment is really invalid and is just now being trapped out. Any insight / suggestions would be appreciated.

Sounds like an Arduino Builder bug. Lots of new bugs have come up with the new arduino builder, particularly relating to the preprocessor.

Go back to 1.6.5r5 - that's the last one where everything was working great, before they introduced the new Arduino Builder in 1.6.6 and it broke all sorts of stuff.

Ah... Posted bug report in github and will return to 1.6.5 Thanks,

-al-

I know you have already received notifications of this thomasow but for anyone else on the forum reading this: The issue is caused by arduino/arduino-builder#106. When the developers wrote the default recipe.preproc.macros for arduino-builder, the new preprocessor added in Arduino IDE 1.6.6 they forgot to add the -mmcu option. Because the ATmegaCAN platform.txt doesn't define recipe.preproc.macros this faulty default recipe is used. I have submitted a pull request to define the correct recipe.preproc.macros in the ATmegaCAN platform.txt thomasonw/ATmegaCAN#1.

Pert,

Thank you - yes. And as more follow up: The problem origin of my problem was deficiencies in the file platform.txt file I had used as the starting point for my porting effort. It was missing a few key 'scripts', including the one you pushed.

I have gone back and re-edited this file, this time using to master platform.txt contained in the Arduino IDE release 1.6.7, and there is of course no problems - plus I picked up some other missing scripts as well.

Bottom line: Problem was caused by a down-revved platform.txt, and the correct action should have been that I used the master actual contained in Arduino IDE release 1.6.7 as the starting point.