Fwd: [PATCH] D11006: Classes inside lambdas are local not nested.

Serge Pavlov sepavloff at gmail.com
Tue Jul 7 11:14:49 PDT 2015


If a lambda used as default argument in a method declaration contained
a local class, that class was incorrectly recognized as nested class.
In this case compiler tried to postpone parsing of this class until
the enclosing class is finished, which caused crashes in some cases.

This change fixes PR13987.

http://reviews.llvm.org/D11006

Files:
  lib/Parse/ParseDeclCXX.cpp
  test/SemaCXX/cxx1y-generic-lambdas.cpp

Index: test/SemaCXX/cxx1y-generic-lambdas.cpp
===================================================================
--- test/SemaCXX/cxx1y-generic-lambdas.cpp
+++ test/SemaCXX/cxx1y-generic-lambdas.cpp
@@ -948,3 +948,30 @@

 auto x = f(0)();
 }
+
+namespace PR13987 {
+class Enclosing {
+  void Method(char c = []()->char {
+    int d = []()->int {
+        struct LocalClass {
+          int Method() { return 0; }
+        };
+      return 0;
+    }();
+    return d; }()
+  );
+};
+
+
+class Enclosing2 {
+  void Method(char c = [](auto x)->char {
+    int d = []()->int {
+        struct LocalClass {
+          int Method() { return 0; }
+        };
+      return 0;
+    }();
+    return d; }(0)
+  );
+};
+}
Index: lib/Parse/ParseDeclCXX.cpp
===================================================================
--- lib/Parse/ParseDeclCXX.cpp
+++ lib/Parse/ParseDeclCXX.cpp
@@ -2824,6 +2824,9 @@
           Parent = Parent->getParent();
         if (Parent->isClassScope())
           break;
+        // Classes defined inside lambda functions are local as well.
+        if (S->getFlags() & Scope::BlockScope)
+          break;
       }
     }
   }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150708/c8adecdf/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D11006.29194.patch
Type: text/x-patch
Size: 1154 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150708/c8adecdf/attachment.bin>


More information about the cfe-commits mailing list