re PR c++/84618 (ICE in build_capture_proxy, at cp/lambda.c:460)
authorPaolo Carlini <paolo.carlini@oracle.com>
Mon, 5 Mar 2018 15:40:15 +0000 (15:40 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Mon, 5 Mar 2018 15:40:15 +0000 (15:40 +0000)
/cp
2018-03-05  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/84618
* parser.c (cp_parser_lambda_introducer): Reject any capture not
involving a VAR_DECL or a PARM_DECL.

/testsuite
2018-03-05  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/84618
* g++.dg/cpp0x/lambda/lambda-ice29.C: New.
* g++.dg/cpp0x/lambda/lambda-ice17.C: Adjust.
* g++.dg/cpp0x/lambda/lambda-ice23.C: Likewise.

From-SVN: r258250

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice17.C
gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice23.C
gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice29.C [new file with mode: 0644]

index e9b0e3bd28e3df0c8ce3fd601554e7147daebb86..5e166350e40a8273f47cfbe6104a7ecddc92fb80 100644 (file)
@@ -1,3 +1,9 @@
+2018-03-05  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/84618
+       * parser.c (cp_parser_lambda_introducer): Reject any capture not
+       involving a VAR_DECL or a PARM_DECL.
+
 2018-03-05  Pádraig Brady  <P@draigBrady.com>
            Jason  Merrill  <jason@redhat.com>
            Nathan Sidwell  <nathan@acm.org>
index e1acb07d29ef5d84b4540a1037bfb612a1e7030a..460b5eaf10e974986777e978edbf5765b2f342ae 100644 (file)
@@ -10377,15 +10377,15 @@ cp_parser_lambda_introducer (cp_parser* parser, tree lambda_expr)
              unqualified_name_lookup_error (capture_id);
              continue;
            }
-         else if (DECL_P (capture_init_expr)
-                  && (!VAR_P (capture_init_expr)
-                      && TREE_CODE (capture_init_expr) != PARM_DECL))
+         else if (!VAR_P (capture_init_expr)
+                  && TREE_CODE (capture_init_expr) != PARM_DECL)
            {
              error_at (capture_token->location,
-                       "capture of non-variable %qD ",
+                       "capture of non-variable %qE ",
                        capture_init_expr);
-             inform (DECL_SOURCE_LOCATION (capture_init_expr),
-                     "%q#D declared here", capture_init_expr);
+             if (DECL_P (capture_init_expr))
+               inform (DECL_SOURCE_LOCATION (capture_init_expr),
+                       "%q#D declared here", capture_init_expr);
              continue;
            }
          if (VAR_P (capture_init_expr)
index 569f040a6bfc36d6f85fc8619a7f960d810549ed..44543c31f0f38fe40c67b630debdac8ef2b95f78 100644 (file)
@@ -1,3 +1,10 @@
+2018-03-05  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/84618
+       * g++.dg/cpp0x/lambda/lambda-ice29.C: New.
+       * g++.dg/cpp0x/lambda/lambda-ice17.C: Adjust.
+       * g++.dg/cpp0x/lambda/lambda-ice23.C: Likewise.
+
 2018-03-05  Olga Makhotina  <olga.makhotina@intel.com>
 
        * g++.dg/other/i386-2.C: Add -mpconfig and -mwbnoinvd.
index 57111fdef6a59c556f62684a6719961ba48044ad..8d84b64cfded39dd676fa4090a908f5c70751f61 100644 (file)
@@ -5,7 +5,7 @@ void foo (int);
 
 void foo (void)
 {
-  [&foo] // { dg-error "cannot capture" }
+  [&foo] // { dg-error "5:capture of non-variable" }
   {
     foo (0);
   };
index b811ad2da5945981fb24dcb2edb22ee2b201a998..4fd2db63967dd600e0e533af1dc92f3af12e552e 100644 (file)
@@ -3,7 +3,7 @@
 
 template <typename T>
 constexpr int r(T x) {
-  auto f = [r,x]() { return r(x); }; // { dg-error "incomplete type" }
+  auto f = [r,x]() { return r(x); }; // { dg-error "13:capture of non-variable" }
   return 0;
 }
 
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice29.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice29.C
new file mode 100644 (file)
index 0000000..80f5b38
--- /dev/null
@@ -0,0 +1,8 @@
+// PR c++/84618
+// { dg-do compile { target c++11 } }
+
+template <int>
+struct S {
+  void b() const;
+  void b() { [b] {}; } // { dg-error "15:capture of non-variable" }
+};