[Bug c++/56772] New: placement new operator does not work inside function template.

meng at g dot clemson.edu gcc-bugzilla@gcc.gnu.org
Thu Mar 28 20:59:00 GMT 2013


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

             Bug #: 56772
           Summary: placement new operator does not work inside function
                    template.
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: meng@g.clemson.edu


g++-4.7.0 emits an error for the following piece of code.

------------------------- BEGIN -----------------------------
#include <cstddef>
#include <new>

template <typename T = size_t>
void f ()
{
   size_t coord [2][2];
   new (&coord) size_t [2][2] 
   {
      {0,0},
      {0,0},
   };
}

int main ()
{
   f<>();
}
-------------------------  END  -----------------------------
The error message was 
error: parenthesized initializer in array new [-fpermissive]
sorry, unimplemented: cannot initialize multi-dimensional array with
initializer

I observed the same behavior on 4.8.0. The problem only occurs inside function
template according to my test. If I made f an ordinary function, the code was
accepted. Clang 3.2 and Visual Studio 2012 all accept the code. These facts led
me to assume this is a bug in g++.

Below is my g++ version.
Reading specs from
/home/meng/gcc/4.7.0/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/specs
COLLECT_GCC=/home/meng/gcc/4.7.0/bin/c++
COLLECT_LTO_WRAPPER=/home/meng/gcc/4.7.0/libexec/gcc/x86_64-unknown-linux-gnu/4.7.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ./configure --prefix=/home/meng/gcc/4.7.0
--enable-languages=c,c++ -disable-multilib
Thread model: posix
gcc version 4.7.0 (GCC)



More information about the Gcc-bugs mailing list