| 1 |
// PR c++/45923 |
| 2 |
// { dg-do compile { target c++11 } } |
| 3 |
|
| 4 |
int f(int); |
| 5 |
|
| 6 |
template <class T> |
| 7 |
constexpr T g(T t) { return f(t); } // { dg-error "f.int" } |
| 8 |
|
| 9 |
int main() |
| 10 |
{ |
| 11 |
constexpr int i = g(1); // { dg-error "g.T" } |
| 12 |
} |
| 13 |
|
| 14 |
// -------------------- |
| 15 |
|
| 16 |
struct complex // { dg-message "no .constexpr. constructor" "" { target { ! implicit_constexpr } } } |
| 17 |
{ |
| 18 |
complex(double r, double i) : re(r), im(i) { } |
| 19 |
constexpr double real() const { return re; } // { dg-error "not a literal type|not usable in a constant expression" "" { target { ! implicit_constexpr } } } |
| 20 |
double imag() const { return im; } |
| 21 |
|
| 22 |
private: |
| 23 |
double re; |
| 24 |
double im; |
| 25 |
}; |
| 26 |
|
| 27 |
constexpr complex co1(0, 1); // { dg-error "19:the type .const complex. of .constexpr. variable .co1. is not literal" "" { target { ! implicit_constexpr } } } |
| 28 |
constexpr double dd2 = co1.real(); // { dg-error "|in .constexpr. expansion of " "" { target { ! implicit_constexpr } } } |
| 29 |
|
| 30 |
// -------------------- |
| 31 |
|
| 32 |
struct base // { dg-message "no .constexpr. constructor" "" { target { ! implicit_constexpr } } } |
| 33 |
{ |
| 34 |
int _M_i; |
| 35 |
base() : _M_i(5) { } |
| 36 |
}; |
| 37 |
|
| 38 |
struct derived : public base // { dg-message "base class" "" { target { ! implicit_constexpr } } } |
| 39 |
{ |
| 40 |
constexpr derived(): base() { } // { dg-error "non-.constexpr. function" "" { target { { ! implicit_constexpr } && c++20_down } } } |
| 41 |
}; |
| 42 |
|
| 43 |
constexpr derived obj; // { dg-error "not literal" "" { target { ! implicit_constexpr } } } |
| 44 |
|
| 45 |
// -------------------- |
| 46 |
|
| 47 |
struct Def |
| 48 |
{ |
| 49 |
int _M_i; // { dg-message "does not initialize" } |
| 50 |
|
| 51 |
constexpr Def() = default; // { dg-error "implicit declaration is not .constexpr." "" { target c++17_down } } |
| 52 |
}; |
| 53 |
|
| 54 |
constexpr Def defobj; // { dg-error "uninitialized" } |