]> granicus.if.org Git - clang/commitdiff
More improvements to abstract type checking. Handle arrays correctly, and make sure...
authorAnders Carlsson <andersca@mac.com>
Mon, 23 Mar 2009 19:10:31 +0000 (19:10 +0000)
committerAnders Carlsson <andersca@mac.com>
Mon, 23 Mar 2009 19:10:31 +0000 (19:10 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67550 91177308-0d34-0410-b5e6-96231b3b80d8

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

index c964daf6fd96f7492a268ebc6edd82514ce7ff2b..d71417b957756f6f5a2771d52162e1623e7d67a5 100644 (file)
@@ -1996,12 +1996,6 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
     } else if (FTI.NumArgs > 0 && FTI.ArgInfo[0].Param != 0) {
       for (unsigned i = 0, e = FTI.NumArgs; i != e; ++i) {
         ParmVarDecl *PVD = (ParmVarDecl *)FTI.ArgInfo[i].Param;
-        
-        // Function parameters cannot have abstract class types.
-        if (RequireNonAbstractType(PVD->getLocation(), PVD->getType(),
-                                   diag::err_abstract_type_in_decl, 
-                                   1 /* parameter type */))
-            InvalidDecl = true;
         Params.push_back(PVD);
       }
     }
@@ -2611,6 +2605,13 @@ Sema::ActOnParamDeclarator(Scope *S, Declarator &D) {
   // FIXME: If a source translation tool needs to see the original type, then
   // we need to consider storing both types (in ParmVarDecl)...
   // 
+  
+  // Parameters can not be abstract class types.
+  if (RequireNonAbstractType(D.getIdentifierLoc(), parmDeclType, 
+                             diag::err_abstract_type_in_decl,
+                             1 /* parameter type */)) 
+    D.setInvalidType(true);
+  
   if (parmDeclType->isArrayType()) {
     // int x[restrict 4] ->  int *restrict
     parmDeclType = Context.getArrayDecayedType(parmDeclType);
index ad2dba7ce4b8c687ad98cc812be56fbe0d7dced2..6f33c005265199ef76423a76875065e9c3dd388c 100644 (file)
@@ -788,6 +788,9 @@ bool Sema::RequireNonAbstractType(SourceLocation Loc, QualType T,
   
   if (!getLangOptions().CPlusPlus)
     return false;
+  
+  if (const ArrayType *AT = Context.getAsArrayType(T))
+    return RequireNonAbstractType(Loc, AT->getElementType(), DiagID, SelID);
     
   const RecordType *RT = T->getAsRecordType();
   if (!RT)
index ac36a1f22df9d1b3348e8173b855d8ea27a035f8..271f1da3adb3c8f86938b2eddc16a3f103958e6a 100644 (file)
@@ -197,6 +197,10 @@ Sema::ActOnCXXTypeConstructExpr(SourceRange TypeRange, TypeTy *TypeRep,
                           diag::err_invalid_incomplete_type_use, FullRange))
     return ExprError();
 
+  if (RequireNonAbstractType(TyBeginLoc, Ty, 
+                             diag::err_allocation_of_abstract_type, 0))
+    return ExprError();
+  
   exprs.release();
   return Owned(new (Context) CXXZeroInitValueExpr(Ty, TyBeginLoc, RParenLoc));
 }
index 1b6099ae7a5616dc6d3f2991243b748b5688cb90..08baacc49d6ee583863f24f29c5dc4b236520379 100644 (file)
@@ -35,3 +35,20 @@ struct S {
   C c; // expected-error {{field type 'C' is an abstract class}}
 };
 
+void t3(const C&);
+
+void f() {
+    C(); // expected-error {{allocation of an object of abstract type 'C'}}
+    t3(C()); // expected-error {{allocation of an object of abstract type 'C'}}
+}
+
+C e[2]; // expected-error {{variable type 'C' is an abstract class}}
+
+void t4(C c[2]); // expected-error {{parameter type 'C' is an abstract class}}
+
+void t5(void (*)(C)); // expected-error {{parameter type 'C' is an abstract class}}
+
+typedef void (*Func)(C); // expected-error {{parameter type 'C' is an abstract class}}
+void t6(Func);
+
+