diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2009-11-10 23:47:18 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2009-11-10 23:47:18 +0000 |
commit | b03bfa55d03ca38922ffedac19225d0832e8d911 (patch) | |
tree | 945acd83aaefec693ba3af51b03f29ebdd43320e /lib/Sema | |
parent | a0203800ea2f93b2ce00fae24d6deac57617268d (diff) |
Diagnose illegally typed operator new/new[].
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86755 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema')
-rw-r--r-- | lib/Sema/SemaDeclCXX.cpp | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 25d14a70be..4be5c62ee0 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -4006,9 +4006,28 @@ bool Sema::CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl) { // found in the rest of this subclause do not apply to them unless // explicitly stated in 3.7.3. // FIXME: Write a separate routine for checking this. For now, just allow it. - if (Op == OO_New || Op == OO_Array_New || - Op == OO_Delete || Op == OO_Array_Delete) + if (Op == OO_Delete || Op == OO_Array_Delete) return false; + + 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_result_type) << FnDecl->getDeclName() + << Context.VoidPtrTy; + return ret; + } // C++ [over.oper]p6: // An operator function shall either be a non-static member |