[cfe-commits] r91187 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDeclCXX.cpp
Anders Carlsson
andersca at mac.com
Fri Dec 11 16:16:02 PST 2009
Author: andersca
Date: Fri Dec 11 18:16:02 2009
New Revision: 91187
URL: http://llvm.org/viewvc/llvm-project?rev=91187&view=rev
Log:
More work on improving the operator delete diagnostics.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=91187&r1=91186&r2=91187&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Dec 11 18:16:02 2009
@@ -2239,10 +2239,20 @@
"%0 cannot be declared static in global scope">;
def err_operator_new_delete_invalid_result_type : Error<
"%0 must return type %1">;
+def err_operator_new_delete_dependent_result_type : Error<
+ "%0 cannot have a dependent return type; use %1 instead">;
def err_operator_new_delete_too_few_parameters : Error<
"%0 must have at least one parameter.">;
+def err_operator_new_delete_template_too_few_parameters : Error<
+ "%0 template must have at least two parameters.">;
+
+def err_operator_new_dependent_param_type : Error<
+ "%0 cannot take a dependent type as first parameter; "
+ "use size_t (%1) instead">;
def err_operator_new_param_type : Error<
"%0 takes type size_t (%1) as first parameter">;
+def err_operator_delete_dependent_param_type : Error<
+ "%0 cannot take a dependent type as first parameter; use %1 instead">;
def err_operator_delete_param_type : Error<
"%0 takes type %1 as first parameter">;
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=91187&r1=91186&r2=91187&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Fri Dec 11 18:16:02 2009
@@ -4626,26 +4626,36 @@
// Each deallocation function shall return void and its first parameter
// shall be void*.
QualType ResultType = FnDecl->getResultType();
- if (!ResultType->isDependentType() && !ResultType->isVoidType()) {
+ if (ResultType->isDependentType())
+ return SemaRef.Diag(FnDecl->getLocation(),
+ diag::err_operator_new_delete_dependent_result_type)
+ << FnDecl->getDeclName() << SemaRef.Context.VoidTy;
+
+ if (!ResultType->isVoidType())
return SemaRef.Diag(FnDecl->getLocation(),
diag::err_operator_new_delete_invalid_result_type)
<< FnDecl->getDeclName() << SemaRef.Context.VoidTy;
- }
- if (FnDecl->getNumParams() == 0) {
+ if (FnDecl->getDescribedFunctionTemplate() && FnDecl->getNumParams() < 2)
+ return SemaRef.Diag(FnDecl->getLocation(),
+ diag::err_operator_new_delete_template_too_few_parameters)
+ << FnDecl->getDeclName();
+ else if (FnDecl->getNumParams() == 0)
return SemaRef.Diag(FnDecl->getLocation(),
diag::err_operator_new_delete_too_few_parameters)
<< FnDecl->getDeclName();
- }
- QualType FirstParamType =
- SemaRef.Context.getCanonicalType(FnDecl->getParamDecl(0)->getType());
- if (!FirstParamType->isDependentType() &&
- FirstParamType != SemaRef.Context.VoidPtrTy) {
+ QualType FirstParamType = FnDecl->getParamDecl(0)->getType();
+ if (FirstParamType->isDependentType())
+ return SemaRef.Diag(FnDecl->getLocation(),
+ diag::err_operator_delete_dependent_param_type)
+ << FnDecl->getDeclName() << SemaRef.Context.VoidPtrTy;
+
+ if (SemaRef.Context.getCanonicalType(FirstParamType) !=
+ SemaRef.Context.VoidPtrTy)
return SemaRef.Diag(FnDecl->getLocation(),
diag::err_operator_delete_param_type)
<< FnDecl->getDeclName() << SemaRef.Context.VoidPtrTy;
- }
return false;
}
More information about the cfe-commits
mailing list