]> granicus.if.org Git - clang/commitdiff
Fix crash on invalid.
authorRichard Trieu <rtrieu@google.com>
Tue, 6 Feb 2018 02:58:21 +0000 (02:58 +0000)
committerRichard Trieu <rtrieu@google.com>
Tue, 6 Feb 2018 02:58:21 +0000 (02:58 +0000)
Don't call a method when the pointer is null.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@324308 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
test/SemaCXX/lambda-expressions.cpp

index 23b3a0ccebf8706ba2ca1a13bfe9888d5fce263f..54723369002475a01281238c242e7e9c4b314606 100644 (file)
@@ -14958,7 +14958,8 @@ static void DoMarkVarDeclReferenced(Sema &SemaRef, SourceLocation Loc,
     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
index de77467b6d5a87d0681ca4866704125f6e8a665e..4565345fc665f6f06e1ec9ec56ca6deec695630a 100644 (file)
@@ -608,3 +608,18 @@ namespace ConversionOperatorDoesNotHaveDeducedReturnType {
   // 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@-1 {{template parameter is declared here}}
+
+template <typename T>
+void Run(const int& points) {
+// expected-note@-1 {{'points' declared here}}
+  auto outer_lambda = []() {
+    auto inner_lambda = [](const X<Points>&) {};
+    // expected-error@-1 {{use of undeclared identifier 'Points'; did you mean 'points'?}}
+    // expected-error@-2 {{template argument for template type parameter must be a type}}
+  };
+}
+}