aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2009-03-23 17:49:10 +0000
committerAnders Carlsson <andersca@mac.com>2009-03-23 17:49:10 +0000
commitb9bbe49f513080b3307e88bdee0d383f4b8c1d4e (patch)
treea5a87cf0d092475fa754028b70939a1b6c31f0f9 /lib
parent374e156647e4250274eb66102839abf0ee9d7fe8 (diff)
It's an error to try to allocate an abstract object using new.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67542 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Sema/Sema.h3
-rw-r--r--lib/Sema/SemaDecl.cpp9
-rw-r--r--lib/Sema/SemaDeclCXX.cpp4
-rw-r--r--lib/Sema/SemaExprCXX.cpp4
4 files changed, 15 insertions, 5 deletions
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h
index 8bc5a6073b..e8702bcea1 100644
--- a/lib/Sema/Sema.h
+++ b/lib/Sema/Sema.h
@@ -1634,7 +1634,8 @@ public:
SourceLocation Loc, SourceRange Range);
std::string getAmbiguousPathsDisplayString(BasePaths &Paths);
- bool RequireNonAbstractType(SourceLocation Loc, QualType T, unsigned SelID);
+ bool RequireNonAbstractType(SourceLocation Loc, QualType T,
+ unsigned DiagID, unsigned SelID);
//===--------------------------------------------------------------------===//
// C++ Overloaded Operators [C++ 13.5]
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index bcb21c33ce..c964daf6fd 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -1641,7 +1641,9 @@ Sema::ActOnVariableDeclarator(Scope* S, Declarator& D, DeclContext* DC,
}
// The variable can not have an abstract class type.
- if (RequireNonAbstractType(D.getIdentifierLoc(), R, 2 /* variable type */))
+ if (RequireNonAbstractType(D.getIdentifierLoc(), R,
+ diag::err_abstract_type_in_decl,
+ 2 /* variable type */))
InvalidDecl = true;
// The variable can not
@@ -1815,6 +1817,7 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
// Check that the return type is not an abstract class type.
if (RequireNonAbstractType(D.getIdentifierLoc(),
R->getAsFunctionType()->getResultType(),
+ diag::err_abstract_type_in_decl,
0 /* return type */))
InvalidDecl = true;
@@ -1996,6 +1999,7 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
// 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);
@@ -3534,7 +3538,8 @@ FieldDecl *Sema::CheckFieldDecl(DeclarationName Name, QualType T,
}
// Fields can not have abstract class types
- if (RequireNonAbstractType(Loc, T, 3 /* field type */))
+ if (RequireNonAbstractType(Loc, T, diag::err_abstract_type_in_decl,
+ 3 /* field type */))
InvalidDecl = true;
// If this is declared as a bit-field, check the bit-field.
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp
index 6be2052fdf..ad2dba7ce4 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -784,7 +784,7 @@ namespace {
}
bool Sema::RequireNonAbstractType(SourceLocation Loc, QualType T,
- unsigned SelID) {
+ unsigned DiagID, unsigned SelID) {
if (!getLangOptions().CPlusPlus)
return false;
@@ -800,7 +800,7 @@ bool Sema::RequireNonAbstractType(SourceLocation Loc, QualType T,
if (!RD->isAbstract())
return false;
- Diag(Loc, diag::err_abstract_type_in_decl) << SelID << RD->getDeclName();
+ Diag(Loc, DiagID) << RD->getDeclName() << SelID;
// Check if we've already emitted the list of pure virtual functions for this
// class.
diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp
index b3d94c372d..ac36a1f22d 100644
--- a/lib/Sema/SemaExprCXX.cpp
+++ b/lib/Sema/SemaExprCXX.cpp
@@ -238,6 +238,10 @@ Sema::ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal,
if (CheckAllocatedType(AllocType, D))
return ExprError();
+ if (RequireNonAbstractType(D.getSourceRange().getBegin(), AllocType,
+ diag::err_allocation_of_abstract_type, 0))
+ return ExprError();
+
QualType ResultType = AllocType->isDependentType()
? Context.DependentTy
: Context.getPointerType(AllocType);