diff options
author | Jason Merrill <jason@redhat.com> | 2017-01-19 10:59:04 -0500 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2017-01-19 10:59:04 -0500 |
commit | a08895999d4a0d4b23b9b3debd08257e6c8122ab (patch) | |
tree | 3a9f3941a9e336b00f7aaed2bc0405740119080c /gcc | |
parent | b32e85fa42678b061f30fa6fc52e0713d980a6df (diff) | |
download | gcc-a08895999d4a0d4b23b9b3debd08257e6c8122ab.zip gcc-a08895999d4a0d4b23b9b3debd08257e6c8122ab.tar.gz gcc-a08895999d4a0d4b23b9b3debd08257e6c8122ab.tar.bz2 |
Array decomposition fix.
* decl.c (check_initializer): Always use build_aggr_init for array
decomposition.
From-SVN: r244639
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 3 | ||||
-rw-r--r-- | gcc/cp/decl.c | 16 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp1z/decomp21.C | 16 |
3 files changed, 27 insertions, 8 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 5b8eb7c..90e230f 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,8 @@ 2017-01-19 Jason Merrill <jason@redhat.com> + * decl.c (check_initializer): Always use build_aggr_init for array + decomposition. + PR c++/79130 - decomposition and direct-initialization * init.c (build_aggr_init): Communicate direct-initialization to build_vec_init. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 75baf94..792ebcc 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -6299,14 +6299,14 @@ check_initializer (tree decl, tree init, int flags, vec<tree, va_gc> **cleanups) if (type == error_mark_node) return NULL_TREE; - if ((type_build_ctor_call (type) || CLASS_TYPE_P (type) - || (DECL_DECOMPOSITION_P (decl) && TREE_CODE (type) == ARRAY_TYPE)) - && !(flags & LOOKUP_ALREADY_DIGESTED) - && !(init && BRACE_ENCLOSED_INITIALIZER_P (init) - && CP_AGGREGATE_TYPE_P (type) - && (CLASS_TYPE_P (type) - || !TYPE_NEEDS_CONSTRUCTING (type) - || type_has_extended_temps (type)))) + if (((type_build_ctor_call (type) || CLASS_TYPE_P (type)) + && !(flags & LOOKUP_ALREADY_DIGESTED) + && !(init && BRACE_ENCLOSED_INITIALIZER_P (init) + && CP_AGGREGATE_TYPE_P (type) + && (CLASS_TYPE_P (type) + || !TYPE_NEEDS_CONSTRUCTING (type) + || type_has_extended_temps (type)))) + || (DECL_DECOMPOSITION_P (decl) && TREE_CODE (type) == ARRAY_TYPE)) { init_code = build_aggr_init_full_exprs (decl, init, flags); diff --git a/gcc/testsuite/g++.dg/cpp1z/decomp21.C b/gcc/testsuite/g++.dg/cpp1z/decomp21.C new file mode 100644 index 0000000..d046ed5 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/decomp21.C @@ -0,0 +1,16 @@ +// { dg-options -std=c++1z } + +int a[3]; +struct S { int b, c, d; } s; +void +foo () +{ + auto [ b, c, d ] = a; + auto [ e, f, g ] = s; + auto [ h, i, j ] { s }; + auto [ k, l, m ] { s, }; + auto [ n, o, p ] { a }; + auto [ q, r, t ] ( s ); + auto [ u, v, w ] ( s, ); // { dg-error "expected primary-expression before '.' token" } + auto [ x, y, z ] ( a ); // { dg-error "expression list treated as compound expression in initializer" "" { target *-*-* } .-1 } +} |