From: Douglas Gregor Date: Tue, 22 Dec 2009 23:42:49 +0000 (+0000) Subject: Allow the first parameter of operator new to be a cv-qualified X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6e790ab61bf4835944971955e84279112833ef0c;p=clang Allow the first parameter of operator new to be a cv-qualified size_t. Also, fix an issue with initialization of parameters in calls, where we weren't removing the cv-qualifiers on the parameter type itself. Fixes PR5823. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91941 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 9e30af8f18..ded89b453c 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -4707,7 +4707,7 @@ CheckOperatorNewDeleteTypes(Sema &SemaRef, const FunctionDecl *FnDecl, << FnDecl->getDeclName() << ExpectedFirstParamType; // Check that the first parameter type is what we expect. - if (SemaRef.Context.getCanonicalType(FirstParamType) != + if (SemaRef.Context.getCanonicalType(FirstParamType).getUnqualifiedType() != ExpectedFirstParamType) return SemaRef.Diag(FnDecl->getLocation(), InvalidParamTypeDiag) << FnDecl->getDeclName() << ExpectedFirstParamType; diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index dd3d2ea2ce..45ee4fd64e 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -737,7 +737,8 @@ void Sema::DeclareGlobalAllocationFunction(DeclarationName Name, // FIXME: Do we need to check for default arguments here? FunctionDecl *Func = cast(*Alloc); if (Func->getNumParams() == 1 && - Context.getCanonicalType(Func->getParamDecl(0)->getType())==Argument) + Context.getCanonicalType( + Func->getParamDecl(0)->getType().getUnqualifiedType()) == Argument) return; } } diff --git a/lib/Sema/SemaInit.h b/lib/Sema/SemaInit.h index 959c55e3d3..5eb819a691 100644 --- a/lib/Sema/SemaInit.h +++ b/lib/Sema/SemaInit.h @@ -102,7 +102,7 @@ private: /// \brief Create the initialization entity for a parameter. InitializedEntity(ParmVarDecl *Parm) - : Kind(EK_Parameter), Parent(0), Type(Parm->getType()), + : Kind(EK_Parameter), Parent(0), Type(Parm->getType().getUnqualifiedType()), VariableOrMember(reinterpret_cast(Parm)) { } /// \brief Create the initialization entity for the result of a diff --git a/test/SemaCXX/new-delete.cpp b/test/SemaCXX/new-delete.cpp index 91f800daea..0e0f630bc4 100644 --- a/test/SemaCXX/new-delete.cpp +++ b/test/SemaCXX/new-delete.cpp @@ -18,7 +18,8 @@ struct V : U { }; -void* operator new(size_t); // expected-note 2 {{candidate}} +// PR5823 +void* operator new(const size_t); // expected-note 2 {{candidate}} void* operator new(size_t, int*); // expected-note 3 {{candidate}} void* operator new(size_t, float*); // expected-note 3 {{candidate}} void* operator new(size_t, S); // expected-note 2 {{candidate}} @@ -215,4 +216,3 @@ static void* f(void* g) { return new (g) X13(); } -