I'm experiencing some weirdness with constexpr in Arduino and am hoping someone here can shed some light. Just wanting to at first toy around with this c++11 feature I tried a trivial example:
constexpr bool oneTrue(bool a, bool b) { return a || b; }
and I get an error stating 'constexprbool does not name a type.' (as is, concatenation between constexpr and bool is in the error message.)
Here's what I've tried:
I fooled around with changing return type and inputs to boolean
I moved the function into a separate compilation unit
I checked that -std=gnu++11
I was using Arduino 1.6.7 and downgraded to 1.6.6
I also tried creating a constexpr which returned an int and a float and both of those compile just fine.
Does anyone have any insight as to why this is happening or better, how to fix it?
Assuming there are no other errors in the code (that you did not post), maybe constexpr is not supported by gcc-avr. Alternative is the use of a normal function or a macro
#define oneTrue(a, b) ((a) || (b))
void setup()
{
bool c = false, d = true;
Serial.begin(9600);
Serial.println(oneTrue(c,d));
}
void loop()
{
// put your main code here, to run repeatedly:
}