| 1 |
// { dg-do assemble } |
| 2 |
// { dg-prune-output "non-static data member initializers" } |
| 3 |
// GROUPS passed initialization |
| 4 |
class foo { |
| 5 |
public: |
| 6 |
int data; |
| 7 |
foo(int dat) { data = dat; } |
| 8 |
}; |
| 9 |
|
| 10 |
class bar { |
| 11 |
public: |
| 12 |
foo f[3] = { 1, 2, 3 }; // works: f[0] = 1, f[1] = 2, f[2] = 3 // { dg-error "" "" { target { ! c++11 } } } ANSI C++ forbids initialization of member f; |
| 13 |
}; |
| 14 |
|
| 15 |
class bar2 { |
| 16 |
public: |
| 17 |
foo f[3] = { foo(1), foo(2), foo(3) }; // { dg-error "" "" { target { ! c++11 } } } ANSI C++ forbids initialization of member f; |
| 18 |
// does not compile -- error: field initializer is not constant |
| 19 |
}; |
| 20 |
|
| 21 |
int main(void) |
| 22 |
{ |
| 23 |
foo f[3] = { foo(1), foo(2), foo(3) }; |
| 24 |
// standard C++ ... and it works too! :) |
| 25 |
return 0; |
| 26 |
} |