diff mbox series

[pushed] c++: allow array mem-init with -fpermissive [PR116634]

Message ID 20241105160446.286616-1-jason@redhat.com
State New
Headers show
Series [pushed] c++: allow array mem-init with -fpermissive [PR116634] | expand

Commit Message

Jason Merrill Nov. 5, 2024, 4:02 p.m. UTC
Tested x86_64-pc-linux-gnu, applying to trunk and 14.

-- 8< --

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.
---
 gcc/cp/init.cc                               | 4 +++-
 gcc/testsuite/g++.dg/diagnostic/aggr-init1.C | 3 ++-
 gcc/testsuite/g++.dg/init/array62.C          | 2 +-
 gcc/testsuite/g++.dg/init/array63.C          | 2 +-
 gcc/testsuite/g++.dg/init/array64.C          | 2 +-
 5 files changed, 8 insertions(+), 5 deletions(-)


base-commit: 6543a214485c0a722152e34de37424f9a0104bbb
diff mbox series

Patch

diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc
index 12c673efb2a..62b3d6f6ce9 100644
--- a/gcc/cp/init.cc
+++ b/gcc/cp/init.cc
@@ -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
diff --git a/gcc/testsuite/g++.dg/diagnostic/aggr-init1.C b/gcc/testsuite/g++.dg/diagnostic/aggr-init1.C
index 3c32124d6fd..906d2564bda 100644
--- a/gcc/testsuite/g++.dg/diagnostic/aggr-init1.C
+++ b/gcc/testsuite/g++.dg/diagnostic/aggr-init1.C
@@ -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));
@@ -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];
 };
diff --git a/gcc/testsuite/g++.dg/init/array62.C b/gcc/testsuite/g++.dg/init/array62.C
index 2a786a36e4e..6d3935d7a66 100644
--- a/gcc/testsuite/g++.dg/init/array62.C
+++ b/gcc/testsuite/g++.dg/init/array62.C
@@ -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 {
diff --git a/gcc/testsuite/g++.dg/init/array63.C b/gcc/testsuite/g++.dg/init/array63.C
index 57e98056168..96bc9a64b26 100644
--- a/gcc/testsuite/g++.dg/init/array63.C
+++ b/gcc/testsuite/g++.dg/init/array63.C
@@ -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};
diff --git a/gcc/testsuite/g++.dg/init/array64.C b/gcc/testsuite/g++.dg/init/array64.C
index e0afdfab39a..bbdd70c6df8 100644
--- a/gcc/testsuite/g++.dg/init/array64.C
+++ b/gcc/testsuite/g++.dg/init/array64.C
@@ -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_;
 };