From f070246d8354582b90ceae186bade027c8259bac Mon Sep 17 00:00:00 2001
From: patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>
Date: Mon, 3 Oct 2011 21:10:11 +0000
Subject: [PATCH] Verify C++ support with CodeSourcery

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4016 42af7a65-404d-4744-a932-0658087f49c3
---
 TODO                 | 19 +++++++++++++++++--
 libxx/libxx_new.cxx  | 14 +++++++++++---
 libxx/libxx_newa.cxx | 16 ++++++++++++----
 3 files changed, 40 insertions(+), 9 deletions(-)

diff --git a/TODO b/TODO
index 028dca512e..256f676890 100644
--- a/TODO
+++ b/TODO
@@ -1,4 +1,4 @@
-NuttX TODO List (Last updated September 28, 2011)
+NuttX TODO List (Last updated October 3, 2011)
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 This file summarizes known NuttX bugs, limitations, inconsistencies with 
@@ -11,7 +11,7 @@ nuttx/
   (1)  Memory Managment (mm/)
   (2)  Signals (sched/, arch/)
   (1)  pthreads (sched/)
-  (1)  C++ Support
+  (2)  C++ Support
   (5)  Binary loaders (binfmt/)
  (16)  Network (net/, drivers/net)
   (2)  USB (drivers/usbdev, drivers/usbhost)
@@ -153,6 +153,21 @@ o pthreads (sched/)
 o C++ Support
   ^^^^^^^^^^^
 
+  Description: The argument of the 'new' operators should take a type of
+               size_t (see libxx/libxx_new.cxx and libxx/libxx_newa.cxx).  But
+               size_t has an unknown underlying.  In the nuttx sys/types.h
+               header file, size_t is typed as uint32_t (which is determined by
+               architecture-specific logic).  But the C++ compiler may believe
+               that size_t is of a different type resulting in compilation errors
+               in the operator.  Using the underlying integer type Instead of
+               size_t seems to resolve the compilation issues.
+  Status:      Kind of open.  There is a workaround.  Setting CONFIG_CXX_NEWLONG=y
+               will define the operators with argument of type unsigned long;
+               Setting CONFIG_CXX_NEWLONG=n will define the operators with argument
+               of type unsigned int.  But this is pretty ugly!  A better solution
+               would be to get ahold of the compilers definition of size_t.
+  Priority:    Low.
+
   Description: Need to call static constructors
   Status:      Open
   Priority:    Low, depends on toolchain.  Call to gcc's built-in static
diff --git a/libxx/libxx_new.cxx b/libxx/libxx_new.cxx
index 49caf74f38..8ec725ca8b 100755
--- a/libxx/libxx_new.cxx
+++ b/libxx/libxx_new.cxx
@@ -58,14 +58,22 @@
 // Name: new
 //
 // NOTE:
-//   This should take a type of size_t, which for ARM GCC is unsigned long.
-//   but size_t may actually be a different different type, in sys/include.h,
-//   it is typed as uint32_t.  Need to REVISIT this.
+//   This should take a type of size_t.  But size_t has an unknown underlying
+//   type.  In the nuttx sys/types.h header file, size_t is typed as uint32_t
+//   (which is determined by architecture-specific logic).  But the C++
+//   compiler may believe that size_t is of a different type resulting in
+//   compilation errors in the operator.  Using the underlying integer type
+//   instead of size_t seems to resolve the compilation issues. Need to
+//   REVISIT this.
 //
 //***************************************************************************
 
 //void *operator new(size_t nbytes)
+#ifdef CONFIG_CXX_NEWLONG
 void *operator new(unsigned long nbytes)
+#else
+void *operator new(unsigned int nbytes)
+#endif
 {
   // We have to allocate something
 
diff --git a/libxx/libxx_newa.cxx b/libxx/libxx_newa.cxx
index e8c214d4d1..855160c412 100755
--- a/libxx/libxx_newa.cxx
+++ b/libxx/libxx_newa.cxx
@@ -58,18 +58,26 @@
 // Name: new
 //
 // NOTE:
-//   This should take a type of size_t, which for ARM GCC is unsigned long.
-//   but size_t may actually be a different different type, in sys/include.h,
-//   it is typed as uint32_t.  Need to REVISIT this.
+//   This should take a type of size_t.  But size_t has an unknown underlying
+//   type.  In the nuttx sys/types.h header file, size_t is typed as uint32_t
+//   (which is determined by architecture-specific logic).  But the C++
+//   compiler may believe that size_t is of a different type resulting in
+//   compilation errors in the operator.  Using the underlying integer type
+//   instead of size_t seems to resolve the compilation issues. Need to
+//   REVISIT this.
 //
 //***************************************************************************
 
 //void *operator new[](size_t size)
+#ifdef CONFIG_CXX_NEWLONG
 void *operator new[](unsigned long nbytes)
+#else
+void *operator new[](unsigned int nbytes)
+#endif
 {
   // We have to allocate something
 
-  if (nbytes< 1)
+  if (nbytes < 1)
     {
       nbytes = 1;
     }
-- 
GitLab