Skip to content

Commit

Permalink
c++: allow array mem-init with -fpermissive [PR116634]
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jicama committed Nov 5, 2024
1 parent 6543a21 commit 3545aab
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 5 deletions.
4 changes: 3 additions & 1 deletion gcc/cp/init.cc
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,9 @@ can_init_array_with_p (tree type, tree init)
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
Expand Down
3 changes: 2 additions & 1 deletion gcc/testsuite/g++.dg/diagnostic/aggr-init1.C
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// PR c++/116634
// { dg-do compile { target c++11 } }
// { dg-additional-options -fpermissive }

namespace std {
using size_t = decltype(sizeof(42));
Expand All @@ -20,7 +21,7 @@ private:
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];
};
Expand Down
2 changes: 1 addition & 1 deletion gcc/testsuite/g++.dg/init/array62.C
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
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 {
Expand Down
2 changes: 1 addition & 1 deletion gcc/testsuite/g++.dg/init/array63.C
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ struct I {
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};
2 changes: 1 addition & 1 deletion gcc/testsuite/g++.dg/init/array64.C
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ typedef UserType Array[my_size];
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_;
};

0 comments on commit 3545aab

Please sign in to comment.