OSDN Git Service

2012-12-15 Richard Guenther <rguenther@suse.de>
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / g++.dg / cpp0x / constexpr-function2.C
1 // { dg-do compile }
2 // { dg-options "-std=gnu++0x" }
3
4 // From N2235
5
6 // Mess with the builtin by redeclaring.
7 constexpr int abs(int x) { return x < 0 ? -x : x; }
8
9 extern "C"
10 {
11   constexpr float
12   squaref(float x) { return x * x; }
13 }
14
15 // implicitly inline, already: warn?
16 inline constexpr double
17 squared(double x) { return x * x; }
18
19 constexpr int squarei(int x) { return x * x; }
20 extern const int side; // { dg-message "not initialized with a constant expression" }
21 constexpr int area = squarei(side); // { dg-error "side|argument" }
22 // error: squarei(side) is not a constant expression
23
24 int next(constexpr int x) // { dg-error "parameter" }
25 { return x + 1; }
26
27 constexpr void f(int x)       // { dg-error "return type .void" }
28 { /* ... */ }
29
30 constexpr int prev(int x)
31 { return --x; }               // { dg-error "--" }
32
33 constexpr int g(int x, int n) // error: body not just ‘‘return expr’’
34 {
35    int r = 1;
36    while (--n > 0) r *= x;
37    return r;
38 } // { dg-error "not a return-statement" }
39
40 constexpr int
41 bar(int x, int y) { return x + y + x * y; } // { dg-error "previously" }
42
43 int bar(int x, int y)        // { dg-error "redefinition" }
44 { return x * 2 + 3 * y; }
45
46 constexpr int twice(int x);  // { dg-message "never defined" }
47 enum { bufsz = twice(256) }; // { dg-error "" } twice() isn’t (yet) defined
48
49 constexpr int fac(int x)
50 { return x > 2 ? x * fac(x - 1) : 1; } // OK