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.
(cherry picked from commit
3545aab00152ed3db1d7ce6ca4e1671dde276980)
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
--- /dev/null
+// PR c++/116634
+// { dg-do compile { target c++11 } }
+// { dg-additional-options -fpermissive }
+
+namespace std {
+ using size_t = decltype(sizeof(42));
+}
+
+class ConstString final {
+public:
+ constexpr ConstString() noexcept: buf(), len(0) {}
+ template<int N>
+ constexpr ConstString(const char (&a)[N]): buf(a), len(N - 1) {}
+ constexpr ConstString(const ConstString &c1): buf(c1.buf), len(static_cast<int>(c1.len)) {}
+
+private:
+ const char* buf;
+ int len;
+};
+
+template<int N>
+struct Any final {
+ constexpr
+ Any(ConstString (&&_vec)[N]) noexcept: vec(_vec){} // { dg-warning "array" }
+
+ ConstString vec[N];
+};
+
+template<int... N1>
+constexpr static
+auto Any_of(const char (&...c1)[N1]) -> Any<static_cast<int>(sizeof...(N1))> {
+ return {{ConstString(c1)...}};
+}
+
+int main() {
+ constexpr static const auto aa1 = Any_of("abcd", "def");
+}
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_;
};