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 9e30af8..ded89b4 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -4707,7 +4707,7 @@
       << 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 dd3d2ea..45ee4fd 100644
--- a/lib/Sema/SemaExprCXX.cpp
+++ b/lib/Sema/SemaExprCXX.cpp
@@ -737,7 +737,8 @@
       // FIXME: Do we need to check for default arguments here?
       FunctionDecl *Func = cast<FunctionDecl>(*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 959c55e..5eb819a 100644
--- a/lib/Sema/SemaInit.h
+++ b/lib/Sema/SemaInit.h
@@ -102,7 +102,7 @@
   
   /// \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<DeclaratorDecl*>(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 91f800d..0e0f630 100644
--- a/test/SemaCXX/new-delete.cpp
+++ b/test/SemaCXX/new-delete.cpp
@@ -18,7 +18,8 @@
 {
 };
 
-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 @@
 {
     return new (g) X13();
 }
-