From: Aaron Ballman Date: Mon, 7 May 2012 00:02:00 +0000 (+0000) Subject: Detecting illegal instantiations of abstract types when using a function-style cast... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=21eb6d4961abf710de3864a537655e9c57903803;p=clang 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 c11c30aa17..dd5de02d15 100644 --- a/lib/Sema/SemaCast.cpp +++ b/lib/Sema/SemaCast.cpp @@ -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, + diag::err_allocation_of_abstract_type)) { msg = 0; return TC_Failed; } diff --git a/test/SemaCXX/abstract.cpp b/test/SemaCXX/abstract.cpp index b164d9eda6..e20a89009b 100644 --- a/test/SemaCXX/abstract.cpp +++ b/test/SemaCXX/abstract.cpp @@ -259,3 +259,17 @@ namespace pr9247 { }; }; } + +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'}} + } +}