[cfe-commits] r67550 - in /cfe/trunk: lib/Sema/SemaDecl.cpp lib/Sema/SemaDeclCXX.cpp lib/Sema/SemaExprCXX.cpp test/SemaCXX/abstract.cpp
Anders Carlsson
andersca at mac.com
Mon Mar 23 12:10:31 PDT 2009
Author: andersca
Date: Mon Mar 23 14:10:31 2009
New Revision: 67550
URL: http://llvm.org/viewvc/llvm-project?rev=67550&view=rev
Log:
More improvements to abstract type checking. Handle arrays correctly, and make sure to check parameter types before they decay.
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/test/SemaCXX/abstract.cpp
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=67550&r1=67549&r2=67550&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Mar 23 14:10:31 2009
@@ -1996,12 +1996,6 @@
} 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 @@
// 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);
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=67550&r1=67549&r2=67550&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Mon Mar 23 14:10:31 2009
@@ -788,6 +788,9 @@
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)
Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=67550&r1=67549&r2=67550&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Mon Mar 23 14:10:31 2009
@@ -197,6 +197,10 @@
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));
}
Modified: cfe/trunk/test/SemaCXX/abstract.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/abstract.cpp?rev=67550&r1=67549&r2=67550&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/abstract.cpp (original)
+++ cfe/trunk/test/SemaCXX/abstract.cpp Mon Mar 23 14:10:31 2009
@@ -35,3 +35,20 @@
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);
+
+
More information about the cfe-commits
mailing list