* decl.c (make_typename_type): s/parameters/arguments/.
[official-gcc.git] / gcc / testsuite / g++.dg / cpp0x / constexpr-inline.C
blobd04257c8c33f1215385fb21a4aabe47e01d147d8
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" }
5 struct entry
7   char const* label;
8   int value;
9 };
11 constexpr bool same (char const *x, char const *y)
13   return !*x && !*y ? true : /* default */ (*x == *y && same (x + 1, y + 1)); 
16 constexpr int
17 keyToValue (char const *label, entry const *entries)
18
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}};
26 int bar ()
28   int result = keyToValue ("Foo", foo); 
29   return result;
32 int baz ()
34   constexpr int result = keyToValue ("Foo", foo); 
35   return result;
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" } }