Go to file
Marek Polacek 753b4679bc c++: Fix P0960 in member init list and array [PR92812]
This patch nails down the remaining P0960 case in PR92812:

  struct A {
    int ar[2];
    A(): ar(1, 2) {} // doesn't work without this patch
  };

Note that when the target object is not of array type, this already
works:

  struct S { int x, y; };
  struct A {
    S s;
    A(): s(1, 2) { } // OK in C++20
  };

because build_new_method_call_1 takes care of the P0960 magic.

It proved to be quite hairy.  When the ()-list has more than one
element, we can always create a CONSTRUCTOR, because the code was
previously invalid.  But when the ()-list has just one element, it
gets all kinds of difficult.  As usual, we have to handle a("foo")
so as not to wrap the STRING_CST in a CONSTRUCTOR.  Always turning
x(e) into x{e} would run into trouble as in c++/93790.  Another
issue was what to do about x({e}): previously, this would trigger
"list-initializer for non-class type must not be parenthesized".
I figured I'd make this work in C++20, so that given

  struct S { int x, y; };

you can do

   S a[2];
   [...]
   A(): a({1, 2}) // initialize a[0] with {1, 2} and a[1] with {}

It also turned out that, as an extension, we support compound literals:

  F (): m((S[1]) { 1, 2 })

so this has to keep working as before.  Moreover, make sure not to trigger
in compiler-generated code, like =default, where array assignment is allowed.

I've factored out a function that turns a TREE_LIST into a CONSTRUCTOR
to simplify handling of P0960.

paren-init35.C also tests this with vector types.

gcc/cp/ChangeLog:

	PR c++/92812
	* cp-tree.h (do_aggregate_paren_init): Declare.
	* decl.c (do_aggregate_paren_init): New.
	(grok_reference_init): Use it.
	(check_initializer): Likewise.
	* init.c (perform_member_init): Handle initializing an array from
	a ()-list.  Use do_aggregate_paren_init.

gcc/testsuite/ChangeLog:

	PR c++/92812
	* g++.dg/cpp0x/constexpr-array23.C: Adjust dg-error.
	* g++.dg/cpp0x/initlist69.C: Likewise.
	* g++.dg/diagnostic/mem-init1.C: Likewise.
	* g++.dg/init/array28.C: Likewise.
	* g++.dg/cpp2a/paren-init33.C: New test.
	* g++.dg/cpp2a/paren-init34.C: New test.
	* g++.dg/cpp2a/paren-init35.C: New test.
	* g++.old-deja/g++.brendan/crash60.C: Adjust dg-error.
	* g++.old-deja/g++.law/init10.C: Likewise.
	* g++.old-deja/g++.other/array3.C: Likewise.
2020-09-03 14:30:06 -04:00
config Daily bump. 2020-08-21 00:16:23 +00:00
contrib Daily bump. 2020-08-27 00:16:27 +00:00
fixincludes
gcc c++: Fix P0960 in member init list and array [PR92812] 2020-09-03 14:30:06 -04:00
gnattools
gotools
include
INSTALL
intl
libada
libatomic
libbacktrace Daily bump. 2020-08-25 00:16:24 +00:00
libcc1 Daily bump. 2020-08-15 00:16:22 +00:00
libcpp
libdecnumber
libffi
libgcc Daily bump. 2020-08-27 00:16:27 +00:00
libgfortran Daily bump. 2020-08-25 00:16:24 +00:00
libgo gotest: use a space rather than a middle dot in target lists 2020-08-27 16:18:01 -07:00
libgomp Daily bump. 2020-08-21 00:16:23 +00:00
libhsail-rt
libiberty Daily bump. 2020-08-27 00:16:27 +00:00
libitm
libobjc
liboffloadmic
libphobos
libquadmath
libsanitizer
libssp
libstdc++-v3 libstdc++: Add workaround for weird std::tuple error [PR 96592] 2020-09-03 16:26:16 +01:00
libvtv
lto-plugin
maintainer-scripts
zlib
.dir-locals.el
.gitattributes
.gitignore
ABOUT-NLS
ar-lib
ChangeLog Daily bump. 2020-08-27 00:16:27 +00:00
ChangeLog.jit
ChangeLog.tree-ssa
compile
config-ml.in
config.guess
config.rpath
config.sub
configure configure: Also check C++11 (flags) for ${build} compiler not only for ${host} 2020-08-20 21:59:00 +02:00
configure.ac configure: Also check C++11 (flags) for ${build} compiler not only for ${host} 2020-08-20 21:59:00 +02:00
COPYING
COPYING3
COPYING3.LIB
COPYING.LIB
COPYING.RUNTIME
depcomp
install-sh
libtool-ldflags
libtool.m4
lt~obsolete.m4
ltgcc.m4
ltmain.sh
ltoptions.m4
ltsugar.m4
ltversion.m4
MAINTAINERS MAINTAINERS: Add myself as OpenACC maintainer 2020-08-26 17:58:22 +02:00
Makefile.def
Makefile.in
Makefile.tpl
missing
mkdep
mkinstalldirs
move-if-change
multilib.am
README
symlink-tree
test-driver
ylwrap

This directory contains the GNU Compiler Collection (GCC).

The GNU Compiler Collection is free software.  See the files whose
names start with COPYING for copying permission.  The manuals, and
some of the runtime libraries, are under different terms; see the
individual source files for details.

The directory INSTALL contains copies of the installation information
as HTML and plain text.  The source of this information is
gcc/doc/install.texi.  The installation information includes details
of what is included in the GCC sources and what files GCC installs.

See the file gcc/doc/gcc.texi (together with other files that it
includes) for usage and porting information.  An online readable
version of the manual is in the files gcc/doc/gcc.info*.

See http://gcc.gnu.org/bugs/ for how to report bugs usefully.

Copyright years on GCC source files may be listed using range
notation, e.g., 1987-2012, indicating that every year in the range,
inclusive, is a copyrightable year that could otherwise be listed
individually.