diff options
author | Jason Merrill <jason@redhat.com> | 2013-06-06 23:13:06 -0400 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2013-06-06 23:13:06 -0400 |
commit | a9429737bda029bc8e668e23986e2d75fcec255f (patch) | |
tree | 70fc133fcddca345d1e4ca13d3c1c6e8de9ff64f | |
parent | e765a228a54752519e75bf6b799ae4ad4bfa72e9 (diff) | |
download | gcc-a9429737bda029bc8e668e23986e2d75fcec255f.zip gcc-a9429737bda029bc8e668e23986e2d75fcec255f.tar.gz gcc-a9429737bda029bc8e668e23986e2d75fcec255f.tar.bz2 |
re PR c++/55520 ([C++11] ICE when capturing a variable-length stack array in lambda; in expand_expr_real_1, at expr.c:9122)
PR c++/55520
* semantics.c (add_capture): Diagnose capture of variable-size
type that is not a C++1y array of runtime bound.
From-SVN: r199780
-rw-r--r-- | gcc/cp/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/cp/semantics.c | 9 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp1y/vla7.C | 12 |
3 files changed, 25 insertions, 0 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index c53a9ff..83e6e87 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2013-06-06 Jason Merrill <jason@redhat.com> + PR c++/55520 + * semantics.c (add_capture): Diagnose capture of variable-size + type that is not a C++1y array of runtime bound. + * decl.c (grokdeclarator): Keep a decl with error type. (grokfield, grokbitfield): Likewise. * pt.c (instantiate_class_template_1): Likewise. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 048a7db..b5c3b0a 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -9487,6 +9487,15 @@ add_capture (tree lambda, tree id, tree initializer, bool by_reference_p, nelts_field, array_type_nelts (type)); type = ctype; } + else if (variably_modified_type_p (type, NULL_TREE)) + { + error ("capture of variable-size type %qT that is not a C++1y array " + "of runtime bound", type); + if (TREE_CODE (type) == ARRAY_TYPE + && variably_modified_type_p (TREE_TYPE (type), NULL_TREE)) + inform (input_location, "because the array element type %qT has " + "variable size", TREE_TYPE (type)); + } else if (by_reference_p) { type = build_reference_type (type); diff --git a/gcc/testsuite/g++.dg/cpp1y/vla7.C b/gcc/testsuite/g++.dg/cpp1y/vla7.C new file mode 100644 index 0000000..df34c82 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/vla7.C @@ -0,0 +1,12 @@ +// PR c++/55520 +// { dg-options "-Wno-vla" } +// { dg-require-effective-target c++11 } + +int main(int argc, char** argv) +{ + int x[1][argc]; + + [&x](int i) { // { dg-error "variable.size" } + x[0][i] = 0; // { dg-prune-output "assignment" } + }(5); +} |