1 // PR c++/53792 - [C++11] improving compiler-time constexpr evaluation
2 // { dg-do compile { target c++11 } }
3 // { dg-additional-options "-O1 -fdump-tree-optimized" }
11 constexpr bool same (char const *x, char const *y)
13 return !*x && !*y ? true : /* default */ (*x == *y && same (x + 1, y + 1));
17 keyToValue (char const *label, entry const *entries)
19 return !entries->label ? entries->value
20 : same (entries->label, label) ? entries->value
21 : /* default */ keyToValue (label, entries + 1);
24 constexpr entry foo[] = {{"Foo", 0}, {"Bar", 1}, {"FooBar", 2}, {0, -1}};
28 int result = keyToValue ("Foo", foo);
34 constexpr int result = keyToValue ("Foo", foo);
38 // Verify that the call to the keyToValue() constexpr function is inlined
39 // regardless of whether or not it's invoked in a constexpr expression.
40 // { dg-final { scan-tree-dump-not "keyToValue" "optimized" } }