aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2009-12-12 00:26:23 +0000
committerAnders Carlsson <andersca@mac.com>2009-12-12 00:26:23 +0000
commita3ccda58913cc1a4b8564e349448b12acc462da7 (patch)
treed56120f1f105bd1e88b9f46d0a50c552a72d060e /lib
parent46991d63642c5a29f62d8b92456f62b0fe564fd0 (diff)
Factor operator new declaration checking out into a separate function.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91189 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/AST/ASTContext.cpp2
-rw-r--r--lib/Sema/SemaDeclCXX.cpp43
2 files changed, 25 insertions, 20 deletions
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index 0d5567370b..cc7055dc68 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -2277,7 +2277,7 @@ QualType ASTContext::getTagDeclType(const TagDecl *Decl) {
/// getSizeType - Return the unique type for "size_t" (C99 7.17), the result
/// of the sizeof operator (C99 6.5.3.4p4). The value is target dependent and
/// needs to agree with the definition in <stddef.h>.
-QualType ASTContext::getSizeType() const {
+CanQualType ASTContext::getSizeType() const {
return getFromTargetType(Target.getSizeType());
}
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp
index 35846602ca..b00b1886f1 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -4605,6 +4605,28 @@ Sema::CheckReferenceInit(Expr *&Init, QualType DeclType,
}
static bool
+CheckOperatorNewDeclaration(Sema &SemaRef, FunctionDecl *FnDecl) {
+ bool ret = false;
+ if (FunctionDecl::param_iterator Param = FnDecl->param_begin()) {
+ QualType SizeTy =
+ SemaRef.Context.getCanonicalType(SemaRef.Context.getSizeType());
+ QualType T = SemaRef.Context.getCanonicalType((*Param)->getType());
+ if (!T->isDependentType() && SizeTy != T) {
+ SemaRef.Diag(FnDecl->getLocation(),
+ diag::err_operator_new_param_type) << FnDecl->getDeclName()
+ << SizeTy;
+ ret = true;
+ }
+ }
+ QualType ResultTy = SemaRef.Context.getCanonicalType(FnDecl->getResultType());
+ if (!ResultTy->isDependentType() && ResultTy != SemaRef.Context.VoidPtrTy)
+ return SemaRef.Diag(FnDecl->getLocation(),
+ diag::err_operator_new_delete_invalid_result_type)
+ << FnDecl->getDeclName() << SemaRef.Context.VoidPtrTy;
+ return ret;
+}
+
+static bool
CheckOperatorDeleteDeclaration(Sema &SemaRef, const FunctionDecl *FnDecl) {
// C++ [basic.stc.dynamic.deallocation]p1:
// A program is ill-formed if deallocation functions are declared in a
@@ -4678,25 +4700,8 @@ bool Sema::CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl) {
if (Op == OO_Delete || Op == OO_Array_Delete)
return CheckOperatorDeleteDeclaration(*this, FnDecl);
- if (Op == OO_New || Op == OO_Array_New) {
- bool ret = false;
- if (FunctionDecl::param_iterator Param = FnDecl->param_begin()) {
- QualType SizeTy = Context.getCanonicalType(Context.getSizeType());
- QualType T = Context.getCanonicalType((*Param)->getType());
- if (!T->isDependentType() && SizeTy != T) {
- Diag(FnDecl->getLocation(),
- diag::err_operator_new_param_type) << FnDecl->getDeclName()
- << SizeTy;
- ret = true;
- }
- }
- QualType ResultTy = Context.getCanonicalType(FnDecl->getResultType());
- if (!ResultTy->isDependentType() && ResultTy != Context.VoidPtrTy)
- return Diag(FnDecl->getLocation(),
- diag::err_operator_new_delete_invalid_result_type)
- << FnDecl->getDeclName() << Context.VoidPtrTy;
- return ret;
- }
+ if (Op == OO_New || Op == OO_Array_New)
+ return CheckOperatorNewDeclaration(*this, FnDecl);
// C++ [over.oper]p6:
// An operator function shall either be a non-static member