aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2017-07-04 09:38:59 +0200
committerJakub Jelinek <jakub@gcc.gnu.org>2017-07-04 09:38:59 +0200
commit9fc1fed43a7ea50803a7a95f3d6a6cea2faf0c27 (patch)
tree66ee4ee692e1ac8a7950aadb39a415afd3485b51
parent6c86bd888ab9a0723b16862961b74bd3e5386356 (diff)
downloadgcc-9fc1fed43a7ea50803a7a95f3d6a6cea2faf0c27.zip
gcc-9fc1fed43a7ea50803a7a95f3d6a6cea2faf0c27.tar.gz
gcc-9fc1fed43a7ea50803a7a95f3d6a6cea2faf0c27.tar.bz2
re PR c++/81258 (ICE on C++1z code with invalid decomposition declaration: in cp_finish_decl, at cp/decl.c:6760)
PR c++/81258 * parser.c (cp_parser_decomposition_declaration): Diagnose invalid forms of structured binding initializers. * g++.dg/cpp1z/decomp21.C (foo): Adjust expected diagnostics. * g++.dg/cpp1z/decomp30.C: New test. From-SVN: r249947
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/parser.c10
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/g++.dg/cpp1z/decomp21.C3
-rw-r--r--gcc/testsuite/g++.dg/cpp1z/decomp30.C12
5 files changed, 36 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 189edcb..59a71da 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2017-07-04 Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/81258
+ * parser.c (cp_parser_decomposition_declaration): Diagnose invalid
+ forms of structured binding initializers.
+
2017-07-03 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/65775
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 3ea7c42..de87449 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -13210,6 +13210,16 @@ cp_parser_decomposition_declaration (cp_parser *parser,
*init_loc = cp_lexer_peek_token (parser->lexer)->location;
tree initializer = cp_parser_initializer (parser, &is_direct_init,
&non_constant_p);
+ if (initializer == NULL_TREE
+ || (TREE_CODE (initializer) == TREE_LIST
+ && TREE_CHAIN (initializer))
+ || (TREE_CODE (initializer) == CONSTRUCTOR
+ && CONSTRUCTOR_NELTS (initializer) != 1))
+ {
+ error_at (loc, "invalid initializer for structured binding "
+ "declaration");
+ initializer = error_mark_node;
+ }
if (decl != error_mark_node)
{
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 03f9357..7a2e1f0 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2017-07-04 Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/81258
+ * g++.dg/cpp1z/decomp21.C (foo): Adjust expected diagnostics.
+ * g++.dg/cpp1z/decomp30.C: New test.
+
2017-07-03 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/65775
diff --git a/gcc/testsuite/g++.dg/cpp1z/decomp21.C b/gcc/testsuite/g++.dg/cpp1z/decomp21.C
index d046ed5..7d3a465 100644
--- a/gcc/testsuite/g++.dg/cpp1z/decomp21.C
+++ b/gcc/testsuite/g++.dg/cpp1z/decomp21.C
@@ -12,5 +12,6 @@ foo ()
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 }
+ // { dg-error "invalid initializer for structured binding declaration" "" { target *-*-* } .-1 }
+ auto [ x, y, z ] ( a );
}
diff --git a/gcc/testsuite/g++.dg/cpp1z/decomp30.C b/gcc/testsuite/g++.dg/cpp1z/decomp30.C
new file mode 100644
index 0000000..23115ad
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/decomp30.C
@@ -0,0 +1,12 @@
+// PR c++/81258
+// { dg-options -std=c++1z }
+
+int a[2];
+auto [b, c] (a);
+auto [d, e] { a };
+auto [f, g] = a;
+auto [h, i] ( a, a ); // { dg-error "invalid initializer for structured binding declaration" }
+auto [j, k] { a, a }; // { dg-error "invalid initializer for structured binding declaration" }
+auto [l, m] = { a }; // { dg-error "deducing from brace-enclosed initializer list requires" }
+auto [n, o] {}; // { dg-error "invalid initializer for structured binding declaration" }
+auto [p, q] (); // { dg-error "invalid initializer for structured binding declaration" }