From ca36cf5ebc9ee855e5bc6aa630e1994e7fba401b Mon Sep 17 00:00:00 2001 From: Richard Trieu Date: Fri, 22 Aug 2014 01:16:44 +0000 Subject: [PATCH] Fix PR20705, crash on invalid. dyn_cast -> dyn_cast_or_null to handle a null pointer. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@216254 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDecl.cpp | 2 +- test/SemaCXX/PR20705.cpp | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 test/SemaCXX/PR20705.cpp diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index c8c381518b..0244d4c4a3 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -9300,7 +9300,7 @@ Sema::FinalizeDeclaration(Decl *ThisDecl) { // Static locals inherit dll attributes from their function. if (VD->isStaticLocal()) { if (FunctionDecl *FD = - dyn_cast(VD->getParentFunctionOrMethod())) { + dyn_cast_or_null(VD->getParentFunctionOrMethod())) { if (Attr *A = getDLLAttr(FD)) { auto *NewAttr = cast(A->clone(getASTContext())); NewAttr->setInherited(true); diff --git a/test/SemaCXX/PR20705.cpp b/test/SemaCXX/PR20705.cpp new file mode 100644 index 0000000000..be2676e563 --- /dev/null +++ b/test/SemaCXX/PR20705.cpp @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s + +template +struct X {}; +auto b = []() { + struct S { + static typename X::type Run(){}; + // expected-error@-1 4{{}} + }; + return 5; +}(); + +template +class PC { +}; + +template +class P { + static typename PC::Type Foo(); + // expected-error@-1 4{{}} +}; -- 2.40.0