From: Richard Smith Date: Sat, 20 Jul 2013 19:41:36 +0000 (+0000) Subject: Add missing check for creating an instance of an abstract class through an X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cfc57085a6eb8036d29164d4294cd95853ee1182;p=clang Add missing check for creating an instance of an abstract class through an implicit conversion sequence. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186769 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index 39c4211892..4fe613e792 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -2415,6 +2415,10 @@ static ExprResult BuildCXXCastArgument(Sema &S, CXXConstructorDecl *Constructor = cast(Method); SmallVector ConstructorArgs; + if (S.RequireNonAbstractType(CastLoc, Ty, + diag::err_allocation_of_abstract_type)) + return ExprError(); + if (S.CompleteConstructorCall(Constructor, From, CastLoc, ConstructorArgs)) return ExprError(); @@ -2500,7 +2504,7 @@ Sema::PerformImplicitConversion(Expr *From, QualType ToType, BeforeToType = Ctor->getParamDecl(0)->getType().getNonReferenceType(); } } - // Watch out for elipsis conversion. + // Watch out for ellipsis conversion. if (!ICS.UserDefined.EllipsisConversion) { ExprResult Res = PerformImplicitConversion(From, BeforeToType, diff --git a/test/SemaCXX/abstract.cpp b/test/SemaCXX/abstract.cpp index e20a89009b..1c5b715775 100644 --- a/test/SemaCXX/abstract.cpp +++ b/test/SemaCXX/abstract.cpp @@ -250,6 +250,13 @@ namespace test4 { }; } +namespace test5 { + struct A { A(int); virtual ~A() = 0; }; // expected-note {{pure virtual method}} + const A &a = 0; // expected-error {{abstract class}} + void f(const A &a = 0); // expected-error {{abstract class}} + void g() { f(0); } // expected-error {{abstract class}} +} + // PR9247: Crash on invalid in clang::Sema::ActOnFinishCXXMemberSpecification namespace pr9247 { struct A {