From 51797d878f42f0d79c8d8dea280295aff1276069 Mon Sep 17 00:00:00 2001 From: Yi Kong Date: Mon, 25 Sep 2017 17:36:54 +0000 Subject: [PATCH] [Sema] Null check in BuildDeclarationNameExpr Qualtype may point to null if we cannot infer its type yet. Fixes PR33843 Differential Revision: https://reviews.llvm.org/D38158 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@314124 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaExpr.cpp | 2 ++ test/SemaCXX/typo-correction-crash.cpp | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 75b09cf218..533e9ec723 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -2803,6 +2803,8 @@ ExprResult Sema::BuildDeclarationNameExpr( { QualType type = VD->getType(); + if (type.isNull()) + return ExprError(); if (auto *FPT = type->getAs()) { // C++ [except.spec]p17: // An exception-specification is considered to be needed when: diff --git a/test/SemaCXX/typo-correction-crash.cpp b/test/SemaCXX/typo-correction-crash.cpp index 0b8383dbaf..b7b9c73a0c 100644 --- a/test/SemaCXX/typo-correction-crash.cpp +++ b/test/SemaCXX/typo-correction-crash.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -std=c++14 -verify %s +// RUN: %clang_cc1 -fsyntax-only -std=c++17 -verify %s auto check1() { return 1; return s; // expected-error {{use of undeclared identifier 's'}} @@ -19,3 +19,5 @@ struct FooRecord { }; FooRecord::NestedNamespace::type x; // expected-error {{no member named 'NestedNamespace' in 'FooRecord'; did you mean 'BarNamespace::NestedNamespace'?}} void cast_expr(int g) { +int(n)(g); } // expected-error {{undeclared identifier 'n'}} + +void bind() { for (const auto& [test,_] : _test_) { }; } // expected-error {{undeclared identifier '_test_'}} -- 2.40.0