Have a class that defines a placement new like varient that updates a pointer
to raw storage via a reference argument.  Here's a stripped down code fragment:

#include <stddef.h> // size_t

class T
{
public:

  void *operator new(size_t size, char *&p);

  T( int &rc);
} ;


void *T::operator new(size_t size, char *&p)
{
  void *o;

  o = (void *) p;

  p += size;

  return(o);
}

T * f ( char *& cur_vardatap )
{
   int rc ;

   T * subTypep = new((char *&)cur_vardatap)
      T( rc );

   return subTypep ;
}


If I build this code with GCC4.3 it doesn't want to generate code that calls
it:

r2.C: In function 'T* f(char*&)':
r2.C:29: error: no matching function for call to 'T::operator new(long unsigned
int, char*)'
r2.C:13: note: candidates are: static void* T::operator new(size_t, char*&)

This code seems a bit fishy to me (casting the input parameter to a reference
type seems odd, and I'm wondering if that cast was added because some other
compiler wouldn't call this operator new either).


This can be worked around this easily enough by changing the code in question
to call global placement new and then increment cur_vardatap by sizeof(T)
afterwards (this specialized new operator is only called in two places so in
all honesty I don't know why the original developer bothered doing all this).

However, regardless of whether this is recoded, is GCC4.3 is correct rejecting
this, or is this a GCC 4.3 regression?  GCC 4.2 and previous compilers accept
this syntax (as do a number of other compilers, IBM xlC, Sun WSPro, intel icpc,
msdev, ...)


-- 
           Summary: operator new placement varient with reference arg not
                    accepted by g++ 4.3
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: peeterj at ca dot ibm dot com
 GCC build triplet: x86_64-unknown-linux-gnu
  GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34862

Reply via email to