* decl.c (make_typename_type): s/parameters/arguments/.
[official-gcc.git] / gcc / testsuite / g++.dg / cpp0x / constexpr-pos1.C
blob8e82ef59eb563d2d0c93e90816b89df31020f856
1 // Positive examples from N3092 (FCD)
2 // { dg-do compile { target c++11 } }
4 #define SA(X) static_assert(X, #X)
6 constexpr int bufsz = 1024; // OK: definition
7 SA (bufsz == 1024);
9 constexpr int square(int x); // OK: declaration
11 struct pixel {
12   int x;
13   int y;
14   // OK: declaration
15   constexpr pixel(int);
17 constexpr pixel::pixel(int a) // OK: definition
18   : x(square(a)), y(square(a))
19 { }
21 constexpr int square(int x) // OK: definition
22 { return x * x; }
24 constexpr pixel large(4); // OK: square defined
25 SA(large.x == 16 && large.y==16);
27 constexpr long long_max() // OK
28 { return 2147483647; }
30 SA(long_max() == 2147483647);
32 constexpr int abs(int x) // OK
33 { return x < 0 ? -x : x; }
35 SA(abs(-1) == 1);
36 SA(abs(24) == 24);
38 struct Length {
39   explicit constexpr Length(int i = 0) : val(i) { }
40 private:
41   int val;
44 constexpr Length l1;
45 constexpr Length l2(12);
47 struct pixel2 {
48   int x, y;
50 constexpr pixel2 ur = { 1294, 1024 };// OK
52 SA(ur.x == 1294 && ur.y == 1024);
54 constexpr const int* addr(const int& ir) { return &ir; } // OK
55 static const int x = 5;
56 extern constexpr const int* xp = addr(x); // OK: (const int*)&(const int&)x
57                                           // is an address contant expression
58 SA(xp == &x);
59 extern constexpr int x2 = *addr(5);
60 SA(x2 == 5);