We've accidentally accepted this forever (at least as far back as 4.7), but
it's always been ill-formed; this was PR59465. And we didn't accept it for
scalar types. But rather than switch to a hard error for this code, let's
give a permerror so affected code can continue to work with -fpermissive.
PR c++/116634
gcc/cp/ChangeLog:
* init.cc (can_init_array_with_p): Allow PR59465 case with
permerror.
gcc/testsuite/ChangeLog:
* g++.dg/diagnostic/aggr-init1.C: Expect warning with -fpermissive.
* g++.dg/init/array62.C: Adjust diagnostic.
* g++.dg/init/array63.C: Adjust diagnostic.
* g++.dg/init/array64.C: Adjust diagnostic.
return true;
}
- return false;
+ permerror (input_location, "array must be initialized "
+ "with a brace-enclosed initializer");
+ return true;
}
/* Initialize MEMBER, a FIELD_DECL, with INIT, a TREE_LIST of
// PR c++/116634
// { dg-do compile { target c++11 } }
+// { dg-additional-options -fpermissive }
namespace std {
using size_t = decltype(sizeof(42));
template<int N>
struct Any final {
constexpr
- Any(ConstString (&&_vec)[N]) noexcept: vec(_vec){} // { dg-error "array" }
+ Any(ConstString (&&_vec)[N]) noexcept: vec(_vec){} // { dg-warning "array" }
ConstString vec[N];
};
struct string {} a[1];
struct pair {
string s[1];
- pair() : s(a) {} // { dg-error "invalid initializer for array member" }
+ pair() : s(a) {} // { dg-error "array must be initialized" }
};
struct S {
struct O {
I a[2];
static I const data[2];
- O() : a(data){} // { dg-error "invalid initializer for array member" }
+ O() : a(data){} // { dg-error "array must be initialized" }
};
I const O::data[2] = {true, false};
class Foo
{
public:
- Foo(Array& m) : m_(m) {}; // { dg-error "invalid initializer for array member" }
+ Foo(Array& m) : m_(m) {}; // { dg-error "array must be initialized" }
private:
Array m_;
};