constexpr weirdness

Hey all.

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?

Thanks in advance!

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:

}

Note: tested in VS2012 C++ with ordinary printf

Hello,

jjtjp: and I get an error stating 'constexprbool does not name a type.' (as is, concatenation between constexpr and bool is in the error message.)

Split the line...

constexpr
bool oneTrue(bool a, bool b) { return a || b; }

void setup() { }
void loop() { }

However...

I checked that -std=gnu++11

...is very likely the problem.

constexpr is obviously somewhat supported since the following compiles and works as it ought:

constexpr int three() { return 3; }

void setup() {
    Serial.println(three());
}

void loop() {
    // empty
}

-std=gnu++11 is the Arduino default since the next release after July 2014. See: https://www.reddit.com/r/arduino/comments/3dia7x/arduino_ide_gets_c11_support/