| 1 |
// PR c++/97523 |
| 2 |
// { dg-do compile { target c++11 } } |
| 3 |
|
| 4 |
// [expr.new]/24: If the new-expression creates an object or an array of |
| 5 |
// objects of class type, access and ambiguity control are done for the |
| 6 |
// [...] constructor selected for the initialization (if any). |
| 7 |
// NB: We only check for a default constructor if the array has a non-constant |
| 8 |
// bound, or there are insufficient initializers. Since an array is an |
| 9 |
// aggregate, we perform aggregate-initialization, which performs |
| 10 |
// copy-initialization, so we only accept converting constructors. |
| 11 |
|
| 12 |
struct T { |
| 13 |
explicit T(); |
| 14 |
T(int); |
| 15 |
}; |
| 16 |
|
| 17 |
struct S { |
| 18 |
S(int); |
| 19 |
}; |
| 20 |
|
| 21 |
void |
| 22 |
fn (int n) |
| 23 |
{ |
| 24 |
new T[1]{}; // { dg-error "explicit constructor" } |
| 25 |
new T[2]{1, 2}; |
| 26 |
new T[3]{1, 2}; // { dg-error "explicit constructor" } |
| 27 |
new T[n]{}; // { dg-error "explicit constructor" } |
| 28 |
|
| 29 |
new S[1]{}; // { dg-error "could not convert" } |
| 30 |
new S[2]{1, 2}; |
| 31 |
new S[3]{1, 2}; // { dg-error "could not convert" } |
| 32 |
new S[n]{}; // { dg-error "could not convert" } |
| 33 |
} |