r324308 - Fix crash on invalid.

Richard Trieu via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 5 18:58:21 PST 2018


Author: rtrieu
Date: Mon Feb  5 18:58:21 2018
New Revision: 324308

URL: http://llvm.org/viewvc/llvm-project?rev=324308&view=rev
Log:
Fix crash on invalid.

Don't call a method when the pointer is null.

Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/SemaCXX/lambda-expressions.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=324308&r1=324307&r2=324308&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Feb  5 18:58:21 2018
@@ -14958,7 +14958,8 @@ static void DoMarkVarDeclReferenced(Sema
     if (RefersToEnclosingScope) {
       LambdaScopeInfo *const LSI =
           SemaRef.getCurLambda(/*IgnoreNonLambdaCapturingScope=*/true);
-      if (LSI && !LSI->CallOperator->Encloses(Var->getDeclContext())) {
+      if (LSI && (!LSI->CallOperator ||
+                  !LSI->CallOperator->Encloses(Var->getDeclContext()))) {
         // If a variable could potentially be odr-used, defer marking it so
         // until we finish analyzing the full expression for any
         // lvalue-to-rvalue

Modified: cfe/trunk/test/SemaCXX/lambda-expressions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/lambda-expressions.cpp?rev=324308&r1=324307&r2=324308&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/lambda-expressions.cpp (original)
+++ cfe/trunk/test/SemaCXX/lambda-expressions.cpp Mon Feb  5 18:58:21 2018
@@ -608,3 +608,18 @@ namespace ConversionOperatorDoesNotHaveD
   // This used to crash in return type deduction for the conversion opreator.
   struct A { int n; void f() { +[](decltype(n)) {}; } };
 }
+
+namespace TypoCorrection {
+template <typename T> struct X {};
+// expected-note at -1 {{template parameter is declared here}}
+
+template <typename T>
+void Run(const int& points) {
+// expected-note at -1 {{'points' declared here}}
+  auto outer_lambda = []() {
+    auto inner_lambda = [](const X<Points>&) {};
+    // expected-error at -1 {{use of undeclared identifier 'Points'; did you mean 'points'?}}
+    // expected-error at -2 {{template argument for template type parameter must be a type}}
+  };
+}
+}




More information about the cfe-commits mailing list