Detecting illegal instantiations of abstract types when using a function-style cast.  Fixed PR12658.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156271 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaCast.cpp b/lib/Sema/SemaCast.cpp
index c11c30a..dd5de02 100644
--- a/lib/Sema/SemaCast.cpp
+++ b/lib/Sema/SemaCast.cpp
@@ -1302,7 +1302,9 @@
                       CastKind &Kind, bool ListInitialization) {
   if (DestType->isRecordType()) {
     if (Self.RequireCompleteType(OpRange.getBegin(), DestType,
-                                 diag::err_bad_dynamic_cast_incomplete)) {
+                                 diag::err_bad_dynamic_cast_incomplete) ||
+        Self.RequireNonAbstractType(OpRange.getBegin(), DestType,

+                                    diag::err_allocation_of_abstract_type)) {
       msg = 0;
       return TC_Failed;
     }
diff --git a/test/SemaCXX/abstract.cpp b/test/SemaCXX/abstract.cpp
index b164d9e..e20a890 100644
--- a/test/SemaCXX/abstract.cpp
+++ b/test/SemaCXX/abstract.cpp
@@ -259,3 +259,17 @@
     };
   };
 }
+
+namespace pr12658 {
+  class C {

+    public:

+      C(int v){}

+      virtual void f() = 0; // expected-note {{unimplemented pure virtual method 'f' in 'C'}}

+  };

+

+  void foo( C& c ) {}

+

+  void bar( void ) {

+    foo(C(99)); // expected-error {{allocating an object of abstract class type 'pr12658::C'}}

+  }
+}