PR c++/85553
[official-gcc.git] / gcc / testsuite / g++.dg / cpp0x / pr53792.C
blobdeb5c1abd8b9900d4eb12839854003578c321b87
1 // PR c++/53792
2 // { dg-do compile { target c++11 } }
3 // { dg-options "-O2 -fdump-tree-optimized" }
4 // { dg-final { scan-tree-dump "return 0" "optimized" } }
6 struct entry {
7   char const* label;
8   int         value;
9 };
11 constexpr bool same(char const *x, char const *y) {
12   return !*x && !*y ? true
13     : /* default */    (*x == *y && same(x+1, y+1));
16 constexpr int keyToValue(char const *label, entry const *entries) {
17   return !entries->label ? entries->value
18        : same(entries->label, label) ? entries->value
19        : /*default*/                   keyToValue(label, entries+1);
22 constexpr entry foo[] = {{"Foo", 0}, {"Bar", 1}, {"FooBar", 2}, {0, -1}};
24 int
25 bar()
27   int result = keyToValue("Foo", foo);
28   return result;