[cfe-commits] r156271 - in /cfe/trunk: lib/Sema/SemaCast.cpp test/SemaCXX/abstract.cpp

Aaron Ballman aaron at aaronballman.com
Sun May 6 17:02:00 PDT 2012


Author: aaronballman
Date: Sun May  6 19:02:00 2012
New Revision: 156271

URL: http://llvm.org/viewvc/llvm-project?rev=156271&view=rev
Log:
Detecting illegal instantiations of abstract types when using a function-style cast.  Fixed PR12658.

Modified:
    cfe/trunk/lib/Sema/SemaCast.cpp
    cfe/trunk/test/SemaCXX/abstract.cpp

Modified: cfe/trunk/lib/Sema/SemaCast.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCast.cpp?rev=156271&r1=156270&r2=156271&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCast.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCast.cpp Sun May  6 19:02:00 2012
@@ -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;
     }

Modified: cfe/trunk/test/SemaCXX/abstract.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/abstract.cpp?rev=156271&r1=156270&r2=156271&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/abstract.cpp (original)
+++ cfe/trunk/test/SemaCXX/abstract.cpp Sun May  6 19:02:00 2012
@@ -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'}}
+  }
+}





More information about the cfe-commits mailing list