[cfe-commits] r151101 - in /cfe/trunk: lib/Parse/ParseExprCXX.cpp test/CXX/expr/expr.prim/expr.prim.general/p4-0x.cpp
Douglas Gregor
dgregor at apple.com
Tue Feb 21 14:51:27 PST 2012
Author: dgregor
Date: Tue Feb 21 16:51:27 2012
New Revision: 151101
URL: http://llvm.org/viewvc/llvm-project?rev=151101&view=rev
Log:
In the conflict between C++11 [expr.prim.general]p4, which declares
that 'this' can be used in the brace-or-equal-initializer of a
non-static data member, and C++11 [expr.prim.lambda]p9, which says
that lambda expressions not in block scope can have no captures, side
fully with C++11 [expr.prim.general]p4 by allowing 'this' to be
captured within these initializers. This seems to be the intent of
non-static data member initializers.
Modified:
cfe/trunk/lib/Parse/ParseExprCXX.cpp
cfe/trunk/test/CXX/expr/expr.prim/expr.prim.general/p4-0x.cpp
Modified: cfe/trunk/lib/Parse/ParseExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExprCXX.cpp?rev=151101&r1=151100&r2=151101&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExprCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExprCXX.cpp Tue Feb 21 16:51:27 2012
@@ -870,8 +870,10 @@
// FIXME: Rename BlockScope -> ClosureScope if we decide to continue using
// it.
- ParseScope BodyScope(this, Scope::BlockScope | Scope::FnScope |
- Scope::DeclScope);
+ unsigned ScopeFlags = Scope::BlockScope | Scope::FnScope | Scope::DeclScope;
+ if (getCurScope()->getFlags() & Scope::ThisScope)
+ ScopeFlags |= Scope::ThisScope;
+ ParseScope BodyScope(this, ScopeFlags);
Actions.ActOnStartOfLambdaDefinition(Intro, D, getCurScope());
Modified: cfe/trunk/test/CXX/expr/expr.prim/expr.prim.general/p4-0x.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/expr/expr.prim/expr.prim.general/p4-0x.cpp?rev=151101&r1=151100&r2=151101&view=diff
==============================================================================
--- cfe/trunk/test/CXX/expr/expr.prim/expr.prim.general/p4-0x.cpp (original)
+++ cfe/trunk/test/CXX/expr/expr.prim/expr.prim.general/p4-0x.cpp Tue Feb 21 16:51:27 2012
@@ -7,3 +7,14 @@
int arr[sizeof(this)]; // expected-error {{invalid use of 'this' outside of a nonstatic member function}}
int sz = sizeof(this); // ok
};
+
+namespace CaptureThis {
+ struct X {
+ int n = 10;
+ int m = [&]{return n + 1; }();
+ int o = [&]{return this->m + 1; }();
+ int p = [&]{return [&](int x) { return this->m + x;}(o); }();
+ };
+
+ X x;
+}
More information about the cfe-commits
mailing list