From: Richard Trieu Date: Fri, 22 Aug 2014 01:16:44 +0000 (+0000) Subject: Fix PR20705, crash on invalid. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ca36cf5ebc9ee855e5bc6aa630e1994e7fba401b;p=clang 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 --- 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{{}} +};