Skip to content
Snippets Groups Projects
Commit d1d8fd28 authored by Marek Polacek's avatar Marek Polacek
Browse files

c++: direct-init of an array of class type [PR59465]

...from another array in a mem-initializer should not be accepted.

We already reject

  struct string {} a[1];
  string x[1](a);

but

  struct pair {
    string s[1];
    pair() : s(a) {}
  };

is wrongly accepted.

It started to be accepted with r0-110915-ga034826198b771:
<https://gcc.gnu.org/pipermail/gcc-patches/2011-August/320236.html>
which was supposed to be a cleanup, not a deliberate change to start
accepting the code.  The build_vec_init_expr code was added in r165976:
<https://gcc.gnu.org/pipermail/gcc-patches/2010-October/297582.html>.

It appears that we do the magic copy array when we have a defaulted
constructor and we generate code for its mem-initializer which
initializes an array.  I also see that we go that path for compound
literals.  So when initializing an array member, we can limit building
up a VEC_INIT_EXPR to those special cases.

	PR c++/59465

gcc/cp/ChangeLog:

	* init.cc (can_init_array_with_p): New.
	(perform_member_init): Check it.

gcc/testsuite/ChangeLog:

	* g++.dg/init/array62.C: New test.
	* g++.dg/init/array63.C: New test.
	* g++.dg/init/array64.C: New test.
parent e4e02c07
No related branches found
No related tags found
No related merge requests found
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment