[cfe-commits] r91189 - in /cfe/trunk: include/clang/AST/ASTContext.h lib/AST/ASTContext.cpp lib/Sema/SemaDeclCXX.cpp

Anders Carlsson andersca at mac.com
Fri Dec 11 16:26:24 PST 2009


Author: andersca
Date: Fri Dec 11 18:26:23 2009
New Revision: 91189

URL: http://llvm.org/viewvc/llvm-project?rev=91189&view=rev
Log:
Factor operator new declaration checking out into a separate function.

Modified:
    cfe/trunk/include/clang/AST/ASTContext.h
    cfe/trunk/lib/AST/ASTContext.cpp
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=91189&r1=91188&r2=91189&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Fri Dec 11 18:26:23 2009
@@ -584,7 +584,7 @@
 
   /// 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

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=91189&r1=91188&r2=91189&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Fri Dec 11 18:26:23 2009
@@ -2277,7 +2277,7 @@
 /// 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());
 }
 

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=91189&r1=91188&r2=91189&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Fri Dec 11 18:26:23 2009
@@ -4605,6 +4605,28 @@
 }
 
 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 @@
   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





More information about the cfe-commits mailing list