aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2011-10-17 14:59:41 -0400
committerJason Merrill <jason@gcc.gnu.org>2011-10-17 14:59:41 -0400
commitc6334ca90632479336ce674606473bc7af32f5c3 (patch)
tree6806ee40173e52c1f7ce29e3124aab289019c678 /gcc
parent7c3297ce400c1bd389236ca12f1728ea1e318169 (diff)
downloadgcc-c6334ca90632479336ce674606473bc7af32f5c3.zip
gcc-c6334ca90632479336ce674606473bc7af32f5c3.tar.gz
gcc-c6334ca90632479336ce674606473bc7af32f5c3.tar.bz2
re PR c++/50736 ([C++0x] ISO_IEC_14882-2011-5.1.2/10 - bug)
PR c++/50736 * parser.c (cp_parser_lambda_introducer): Check for more invalid captures. From-SVN: r180105
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/parser.c29
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/lambda/lambda-capture-neg.C15
4 files changed, 51 insertions, 4 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 453dce1..ed7d832 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2011-10-17 Jason Merrill <jason@redhat.com>
+
+ PR c++/50736
+ * parser.c (cp_parser_lambda_introducer): Check for more
+ invalid captures.
+
2011-10-17 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/44524
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index ea0c4dc..bf362f2 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -7630,6 +7630,31 @@ cp_parser_lambda_introducer (cp_parser* parser, tree lambda_expr)
/*ambiguous_decls=*/NULL,
capture_token->location);
+ if (capture_init_expr == error_mark_node)
+ {
+ unqualified_name_lookup_error (capture_id);
+ continue;
+ }
+ else if (DECL_P (capture_init_expr)
+ && (TREE_CODE (capture_init_expr) != VAR_DECL
+ && TREE_CODE (capture_init_expr) != PARM_DECL))
+ {
+ error_at (capture_token->location,
+ "capture of non-variable %qD ",
+ capture_init_expr);
+ inform (0, "%q+#D declared here", capture_init_expr);
+ continue;
+ }
+ if (TREE_CODE (capture_init_expr) == VAR_DECL
+ && decl_storage_duration (capture_init_expr) != dk_auto)
+ {
+ pedwarn (capture_token->location, 0, "capture of variable "
+ "%qD with non-automatic storage duration",
+ capture_init_expr);
+ inform (0, "%q+#D declared here", capture_init_expr);
+ continue;
+ }
+
capture_init_expr
= finish_id_expression
(capture_id,
@@ -7647,10 +7672,6 @@ cp_parser_lambda_introducer (cp_parser* parser, tree lambda_expr)
capture_token->location);
}
- if (TREE_CODE (capture_init_expr) == IDENTIFIER_NODE)
- capture_init_expr
- = unqualified_name_lookup_error (capture_init_expr);
-
if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr) != CPLD_NONE
&& !explicit_init_p)
{
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 3a6edad..3a3cef9 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2011-10-17 Jason Merrill <jason@redhat.com>
+
+ PR c++/50736
+ * g++.dg/cpp0x/lambda/lambda-capture-neg.C: New.
+
2011-10-17 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/44524
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-capture-neg.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-capture-neg.C
new file mode 100644
index 0000000..82cc984
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-capture-neg.C
@@ -0,0 +1,15 @@
+// PR c++/50736
+// { dg-options "-std=c++0x -pedantic-errors" }
+
+int i;
+void f();
+typedef int T;
+
+int main()
+{
+ [i]{}; // { dg-error "non-automatic" }
+ [f]{}; // { dg-error "non-variable" }
+ [T]{}; // { dg-error "non-variable" }
+}
+
+struct A { };