]> granicus.if.org Git - clang/commitdiff
Add missing check for creating an instance of an abstract class through an
authorRichard Smith <richard-llvm@metafoo.co.uk>
Sat, 20 Jul 2013 19:41:36 +0000 (19:41 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Sat, 20 Jul 2013 19:41:36 +0000 (19:41 +0000)
implicit conversion sequence.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186769 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 39c4211892229823fcafd3fbed7e059c87c3aaeb..4fe613e792c6ae927658fefde5e95bec9dac2f91 100644 (file)
@@ -2415,6 +2415,10 @@ static ExprResult BuildCXXCastArgument(Sema &S,
     CXXConstructorDecl *Constructor = cast<CXXConstructorDecl>(Method);
     SmallVector<Expr*, 8> 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,
index e20a89009bd98f3848262940b65699fe0ef1d601..1c5b715775d5924de635ccf60d41899975cc6796 100644 (file)
@@ -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 {