FlashStringHelper problems 1.6.5 to 1.6.6

This code compiles and functions perfectly in Arduino 1.6.5:

#include <WString.h>

void setup() {
  Serial.print(test(true));
}

void loop() {}

const __FlashStringHelper* test(bool temp)
{
  if (temp)
  {
    return F("x");
  }
  return F("y");
}

Arduino Build output:

Sketch uses 1,474 bytes (4%) of program storage space. Maximum is 32,256 bytes.
Global variables use 182 bytes (8%) of dynamic memory, leaving 1,866 bytes for local variables. Maximum is 2,048 bytes.

Then I upgraded to 1.6.6 and now I get this:

Arduino: 1.6.6 (Windows 10), Board: "Arduino/Genuino Uno"

C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware "C:\Program Files (x86)\Arduino\hardware" -tools "C:\Program Files (x86)\Arduino\tools-builder" -tools "C:\Program Files (x86)\Arduino\hardware\tools\avr" -built-in-libraries "C:\Program Files (x86)\Arduino\libraries" -libraries "C:\Users\taylorc\Documents\Arduino\libraries" -fqbn=arduino:avr:uno -ide-version=10606 -build-path "C:\Users\taylorc\AppData\Local\Temp\build1e9696e3d4f345a0e410f31666f6c819.tmp" -warnings=none -prefs=build.warn_data_percentage=75 -verbose "C:\Users\taylorc\AppData\Local\Temp\arduino_1e9696e3d4f345a0e410f31666f6c819\sketch_nov22a.ino"
C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware "C:\Program Files (x86)\Arduino\hardware" -tools "C:\Program Files (x86)\Arduino\tools-builder" -tools "C:\Program Files (x86)\Arduino\hardware\tools\avr" -built-in-libraries "C:\Program Files (x86)\Arduino\libraries" -libraries "C:\Users\taylorc\Documents\Arduino\libraries" -fqbn=arduino:avr:uno -ide-version=10606 -build-path "C:\Users\taylorc\AppData\Local\Temp\build1e9696e3d4f345a0e410f31666f6c819.tmp" -warnings=none -prefs=build.warn_data_percentage=75 -verbose "C:\Users\taylorc\AppData\Local\Temp\arduino_1e9696e3d4f345a0e410f31666f6c819\sketch_nov22a.ino"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -w -x c++ -M -MG -MP -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10606 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "C:\Users\taylorc\AppData\Local\Temp\build1e9696e3d4f345a0e410f31666f6c819.tmp\sketch\sketch_nov22a.ino.cpp"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -w -x c++ -M -MG -MP -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10606 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "C:\Users\taylorc\AppData\Local\Temp\build1e9696e3d4f345a0e410f31666f6c819.tmp\sketch\sketch_nov22a.ino.cpp"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -w -x c++ -M -MG -MP -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10606 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "C:\Users\taylorc\AppData\Local\Temp\build1e9696e3d4f345a0e410f31666f6c819.tmp\sketch\sketch_nov22a.ino.cpp"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -w -x c++ -M -MG -MP -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10606 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "C:\Users\taylorc\AppData\Local\Temp\build1e9696e3d4f345a0e410f31666f6c819.tmp\sketch\sketch_nov22a.ino.cpp"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -w -x c++ -M -MG -MP -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10606 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "C:\Users\taylorc\AppData\Local\Temp\build1e9696e3d4f345a0e410f31666f6c819.tmp\sketch\sketch_nov22a.ino.cpp"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10606 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "C:\Users\taylorc\AppData\Local\Temp\build1e9696e3d4f345a0e410f31666f6c819.tmp\sketch\sketch_nov22a.ino.cpp"
"C:\Program Files (x86)\Arduino\tools-builder\ctags\5.8-arduino2/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns "C:\Users\taylorc\AppData\Local\Temp\build1e9696e3d4f345a0e410f31666f6c819.tmp\preproc\ctags_target.cpp"
"C:\Program Files (x86)\Arduino\tools-builder\ctags\5.8-arduino2/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns "C:\Users\taylorc\AppData\Local\Temp\build1e9696e3d4f345a0e410f31666f6c819.tmp\preproc\ctags_target.cpp"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10606 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "C:\Users\taylorc\AppData\Local\Temp\build1e9696e3d4f345a0e410f31666f6c819.tmp\sketch\sketch_nov22a.ino.cpp" -o "C:\Users\taylorc\AppData\Local\Temp\build1e9696e3d4f345a0e410f31666f6c819.tmp\sketch\sketch_nov22a.ino.cpp.o"
sketch_nov22a:5: error: 'const__FlashStringHelper' does not name a type

 }

 ^

C:\Users\taylorc\AppData\Local\Temp\arduino_1e9696e3d4f345a0e410f31666f6c819\sketch_nov22a.ino: In function 'void setup()':

sketch_nov22a:4: error: 'test' was not declared in this scope

   Serial.print(test(true));

                         ^

exit status 1
'const__FlashStringHelper' does not name a type

Note that, besides the build failure, the line numbers aren’t even correct in the error output! The “const __FlashStringHelper” is used on line 7, not 5.

I make extensive use of Flash strings to save valuable RAM and now almost every project I have fails to build. How can I rectify this problem?

const__FlashStringHelper

or

const __FlashStringHelper

Charles: How can I rectify this problem?

Add this line near the top of your sketch:

const __FlashStringHelper* test(bool temp);

The problem is that the prototype for test() is being incorrectly generated so if you declare the prototype manually then it fixes the problem.

I think this is a bug with the new preprocessor arduino-builder added in Arduino IDE 1.6.6. I have reported your issue here: https://github.com/arduino/arduino-builder/issues/69

So it wasn't the lack of a space after "const" as the error indicated?

"'const__FlashStringHelper' does not name a type"

I just thought it was a simple typo.

Charles’ sketch has the space. It’s the automatically generated prototype that’s missing the space. This is what the sketch looks like in the build folder after arduino-builder has done its magic:

#include <Arduino.h>
#line 1
#line 1 "C:\\Users\\per\\AppData\\Local\\Temp\\arduino_27554574f2108444c4cb69bfa573e6f0\\sketch_nov22c.ino"
#include <WString.h>

#line 3 "C:\\Users\\per\\AppData\\Local\\Temp\\arduino_27554574f2108444c4cb69bfa573e6f0\\sketch_nov22c.ino"
void setup();
#line 7 "C:\\Users\\per\\AppData\\Local\\Temp\\arduino_27554574f2108444c4cb69bfa573e6f0\\sketch_nov22c.ino"
void loop();
#line 9 "C:\\Users\\per\\AppData\\Local\\Temp\\arduino_27554574f2108444c4cb69bfa573e6f0\\sketch_nov22c.ino"
const__FlashStringHelper* test(bool temp);
#line 3
void setup() {
  Serial.print(test(true));
}

void loop() {}

const __FlashStringHelper* test(bool temp)
{
  if (temp)
  {
    return F("x");
  }
  return F("y");
}

Right. Now it makes sense. I just thought that maybe he'd accidentally removed the space, when I saw the compiler error. Naughty compiler. :)

Thanks! Adding the prototype fixes the problem.

Is this a bug in the Arduino code generator? Is it perhaps not adding a space somewhere it should and therefore generating bad headers?

What about the incorrect line number? That's a much bigger deal because in my actual code that's hundreds of lines long, it's not always so obvious where the error actually was.

Charles:
Is this a bug in the Arduino code generator? Is it perhaps not adding a space somewhere it should and therefore generating bad headers?

I believe so. It might also be an issue with the ctags tool that arduino-builder uses as in issue arduino-builder/#27 I’ll report back here once I get information from the developers.

Charles:
What about the incorrect line number? That’s a much bigger deal because in my actual code that’s hundreds of lines long, it’s not always so obvious where the error actually was.

The reason the line number looks wrong is that the error is caused by the hidden automatically generated function prototype. It’s actually showing the line number of that prototype you can see in the code I posted in comment #4. So that’s not a bug but certainly confusing and it would be nice if there was a way for the Arduino IDE to explain what is happening when the error is caused by hidden code. I’ve been severely confused by similar situations in the past. If you ever get an error on a line number that seems wrong then take a look at the .cpp file in the sketch folder inside of the build folder.

Also, I just returned to my main code, which is too large to post. I added the function prototype but now I'm getting this error on compile:

'const__FlashStringHelper' does not name a type

I have triple-checked.... There is NO typo in my code, and it compiles flawlessly under 1.6.5.

Arduino reports the error to be in the middle of a large block of comment text. :-/

Attach the sketch and I'll take a look at it.

I appreciate the offer, but the problem isn't in my sketch. 1.6.6 is generating function prototypes for "const __FlashStringHelper" without a space. This is clearly demonstrated by the example code in my first post.

I have confirmed the bug still exists in the latest hourly build as of the time of this post.

Reverting to 1.6.5.

Opened Arduino bug ticket #4202

Charles: I appreciate the offer, but the problem isn't in my sketch. 1.6.6 is generating function prototypes for "const __FlashStringHelper" without a space. This is clearly demonstrated by the example code in my first post.

Um... yes I know this, I'm the one who told you that was the problem. I also showed you how you can make your sketch compile in 1.6.6 by manually creating the function prototype.

Charles: Opened Arduino bug ticket #4202

If you had read my comment #2 you would see that I already had opened a ticket so you just created a duplicate one which wastes the developer's time.