]> granicus.if.org Git - clang/commitdiff
Detecting illegal instantiations of abstract types when using a function-style cast...
authorAaron Ballman <aaron@aaronballman.com>
Mon, 7 May 2012 00:02:00 +0000 (00:02 +0000)
committerAaron Ballman <aaron@aaronballman.com>
Mon, 7 May 2012 00:02:00 +0000 (00:02 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156271 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaCast.cpp
test/SemaCXX/abstract.cpp

index c11c30aa1700d3b2a86b0f00fad007c47d0538c5..dd5de02d15db813585575730f239cc78a3daee8a 100644 (file)
@@ -1302,7 +1302,9 @@ TryStaticImplicitCast(Sema &Self, ExprResult &SrcExpr, QualType DestType,
                       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,\r
+                                    diag::err_allocation_of_abstract_type)) {
       msg = 0;
       return TC_Failed;
     }
index b164d9eda6a52c5992cc3d744ab2930ac054fe4d..e20a89009bd98f3848262940b65699fe0ef1d601 100644 (file)
@@ -259,3 +259,17 @@ namespace pr9247 {
     };
   };
 }
+
+namespace pr12658 {
+  class C {\r
+    public:\r
+      C(int v){}\r
+      virtual void f() = 0; // expected-note {{unimplemented pure virtual method 'f' in 'C'}}\r
+  };\r
+\r
+  void foo( C& c ) {}\r
+\r
+  void bar( void ) {\r
+    foo(C(99)); // expected-error {{allocating an object of abstract class type 'pr12658::C'}}\r
+  }
+}