summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2013-05-03 19:16:22 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2013-05-03 19:16:22 +0000
commitfa11fd669f45fe5a439d83c70de63f663ef57eb9 (patch)
tree783c04b2c57b0efcaa490fe90e85a8d884efd866 /clang
parent4ffff2791f9d92069d02b3f33274885cf433cebd (diff)
downloadbcm5719-llvm-fa11fd669f45fe5a439d83c70de63f663ef57eb9.tar.gz
bcm5719-llvm-fa11fd669f45fe5a439d83c70de63f663ef57eb9.zip
PR15906: The body of a lambda is not an evaluated subexpression; don't visit it when visiting such subexpressions.
llvm-svn: 181046
Diffstat (limited to 'clang')
-rw-r--r--clang/include/clang/AST/EvaluatedExprVisitor.h11
-rw-r--r--clang/lib/Sema/SemaDecl.cpp2
-rw-r--r--clang/test/SemaCXX/uninitialized.cpp12
3 files changed, 23 insertions, 2 deletions
diff --git a/clang/include/clang/AST/EvaluatedExprVisitor.h b/clang/include/clang/AST/EvaluatedExprVisitor.h
index eb186c217e3..2e3cbfad919 100644
--- a/clang/include/clang/AST/EvaluatedExprVisitor.h
+++ b/clang/include/clang/AST/EvaluatedExprVisitor.h
@@ -55,7 +55,7 @@ public:
// Only the selected subexpression matters; the other one is not evaluated.
return this->Visit(E->getChosenSubExpr(Context));
}
-
+
void VisitDesignatedInitExpr(DesignatedInitExpr *E) {
// Only the actual initializer matters; the designators are all constant
// expressions.
@@ -72,6 +72,15 @@ public:
return static_cast<ImplClass*>(this)->VisitExpr(CE);
}
+ void VisitLambdaExpr(LambdaExpr *LE) {
+ // Only visit the capture initializers, and not the body.
+ for (LambdaExpr::capture_init_iterator I = LE->capture_init_begin(),
+ E = LE->capture_init_end();
+ I != E; ++I)
+ if (*I)
+ this->Visit(*I);
+ }
+
/// \brief The basis case walks all of the children of the statement or
/// expression, assuming they are all potentially evaluated.
void VisitStmt(Stmt *S) {
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 5e0d7f2a0ae..f5b4823fdb7 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -7212,7 +7212,7 @@ namespace {
return;
}
Inherited::VisitUnaryOperator(E);
- }
+ }
void VisitObjCMessageExpr(ObjCMessageExpr *E) { return; }
diff --git a/clang/test/SemaCXX/uninitialized.cpp b/clang/test/SemaCXX/uninitialized.cpp
index 2aa56623f69..665cfe7e911 100644
--- a/clang/test/SemaCXX/uninitialized.cpp
+++ b/clang/test/SemaCXX/uninitialized.cpp
@@ -511,3 +511,15 @@ namespace operators {
int x = x = 5;
}
+
+namespace lambdas {
+ struct A {
+ template<typename T> A(T) {}
+ int x;
+ };
+ A a0([] { return a0.x; }); // ok
+ void f() {
+ A a1([=] { return a1.x; }); // expected-warning{{variable 'a1' is uninitialized when used within its own initialization}}
+ A a2([&] { return a2.x; }); // ok
+ }
+}
OpenPOWER on IntegriCloud