]> granicus.if.org Git - clang/commitdiff
Factor operator new declaration checking out into a separate function.
authorAnders Carlsson <andersca@mac.com>
Sat, 12 Dec 2009 00:26:23 +0000 (00:26 +0000)
committerAnders Carlsson <andersca@mac.com>
Sat, 12 Dec 2009 00:26:23 +0000 (00:26 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91189 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/ASTContext.h
lib/AST/ASTContext.cpp
lib/Sema/SemaDeclCXX.cpp

index fffe45b6c957695dbfb7aec6fbfc6701ba618f5c..3fc5aabde32c75cffaab8a2c00c91333d0fce10d 100644 (file)
@@ -584,7 +584,7 @@ public:
 
   /// getSizeType - Return the unique type for "size_t" (C99 7.17), defined
   /// in <stddef.h>. The sizeof operator requires this (C99 6.5.3.4p4).
-  QualType getSizeType() const;
+  CanQualType getSizeType() const;
 
   /// getWCharType - In C++, this returns the unique wchar_t type.  In C99, this
   /// returns a type compatible with the type defined in <stddef.h> as defined
index 0d5567370b93d7d8e8d2589c1dba7445bb8ffcdb..cc7055dc68b850214b40388b69545fbf4185b3a6 100644 (file)
@@ -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());
 }
 
index 35846602ca05879f1bf98c8d8d3bfad265a1fa3b..b00b1886f14b0e26dbba3185cbaf6cdbb6b84a8e 100644 (file)
@@ -4604,6 +4604,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:
@@ -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