annotate gcc/testsuite/g++.dg/cpp0x/constexpr-function2.C @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 // { dg-do compile { target c++11 } }
kono
parents:
diff changeset
2
kono
parents:
diff changeset
3 // From N2235
kono
parents:
diff changeset
4
kono
parents:
diff changeset
5 // Mess with the builtin by redeclaring.
kono
parents:
diff changeset
6 constexpr int abs(int x) { return x < 0 ? -x : x; }
kono
parents:
diff changeset
7
kono
parents:
diff changeset
8 extern "C"
kono
parents:
diff changeset
9 {
kono
parents:
diff changeset
10 constexpr float
kono
parents:
diff changeset
11 squaref(float x) { return x * x; }
kono
parents:
diff changeset
12 }
kono
parents:
diff changeset
13
kono
parents:
diff changeset
14 // implicitly inline, already: warn?
kono
parents:
diff changeset
15 inline constexpr double
kono
parents:
diff changeset
16 squared(double x) { return x * x; }
kono
parents:
diff changeset
17
kono
parents:
diff changeset
18 constexpr int squarei(int x) { return x * x; }
kono
parents:
diff changeset
19 extern const int side; // { dg-message "not initialized with a constant expression" }
kono
parents:
diff changeset
20 constexpr int area = squarei(side); // { dg-error "side|argument" }
kono
parents:
diff changeset
21 // error: squarei(side) is not a constant expression
kono
parents:
diff changeset
22
kono
parents:
diff changeset
23 int next(constexpr int x) // { dg-error "parameter" }
kono
parents:
diff changeset
24 { return x + 1; }
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 constexpr void f(int x) // { dg-error "return type .void" "" { target c++11_only } }
kono
parents:
diff changeset
27 { /* ... */ }
kono
parents:
diff changeset
28
kono
parents:
diff changeset
29 constexpr int prev(int x)
kono
parents:
diff changeset
30 { return --x; } // { dg-error "--" "" { target c++11_only } }
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 constexpr int g(int x, int n) // error: body not just ‘‘return expr’’
kono
parents:
diff changeset
33 {
kono
parents:
diff changeset
34 int r = 1;
kono
parents:
diff changeset
35 while (--n > 0) r *= x;
kono
parents:
diff changeset
36 return r;
kono
parents:
diff changeset
37 } // { dg-error "not a return-statement" "" { target c++11_only } }
kono
parents:
diff changeset
38
kono
parents:
diff changeset
39 constexpr int
kono
parents:
diff changeset
40 bar(int x, int y) { return x + y + x * y; } // { dg-message "previously" }
kono
parents:
diff changeset
41
kono
parents:
diff changeset
42 int bar(int x, int y) // { dg-error "redefinition" }
kono
parents:
diff changeset
43 { return x * 2 + 3 * y; }
kono
parents:
diff changeset
44
kono
parents:
diff changeset
45 constexpr int twice(int x); // { dg-message "never defined" }
kono
parents:
diff changeset
46 enum { bufsz = twice(256) }; // { dg-error "" } twice() isn’t (yet) defined
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 constexpr int fac(int x)
kono
parents:
diff changeset
49 { return x > 2 ? x * fac(x - 1) : 1; } // OK