]> granicus.if.org Git - clang/commitdiff
Fix PR20705, crash on invalid.
authorRichard Trieu <rtrieu@google.com>
Fri, 22 Aug 2014 01:16:44 +0000 (01:16 +0000)
committerRichard Trieu <rtrieu@google.com>
Fri, 22 Aug 2014 01:16:44 +0000 (01:16 +0000)
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
test/SemaCXX/PR20705.cpp [new file with mode: 0644]

index c8c381518b19a7faa56c8f1981577ff5674e3b7f..0244d4c4a307770f01b811ab841b5947b69dde72 100644 (file)
@@ -9300,7 +9300,7 @@ Sema::FinalizeDeclaration(Decl *ThisDecl) {
   // Static locals inherit dll attributes from their function.
   if (VD->isStaticLocal()) {
     if (FunctionDecl *FD =
-            dyn_cast<FunctionDecl>(VD->getParentFunctionOrMethod())) {
+            dyn_cast_or_null<FunctionDecl>(VD->getParentFunctionOrMethod())) {
       if (Attr *A = getDLLAttr(FD)) {
         auto *NewAttr = cast<InheritableAttr>(A->clone(getASTContext()));
         NewAttr->setInherited(true);
diff --git a/test/SemaCXX/PR20705.cpp b/test/SemaCXX/PR20705.cpp
new file mode 100644 (file)
index 0000000..be2676e
--- /dev/null
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s
+
+template <typename T>
+struct X {};
+auto b = []() {
+  struct S {
+    static typename X<decltype(int)>::type Run(){};
+    // expected-error@-1 4{{}}
+  };
+  return 5;
+}();
+
+template <typename T1, typename T2>
+class PC {
+};
+
+template <typename T>
+class P {
+  static typename PC<T, Invalid>::Type Foo();
+  // expected-error@-1 4{{}}
+};