Bug 56772 - placement new operator does not work inside function template for array types.
Summary: placement new operator does not work inside function template for array types.
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: 4.8.1
Assignee: Jason Merrill
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-03-28 20:59 UTC by rigaje
Modified: 2013-04-01 21:22 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-04-01 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description rigaje 2013-03-28 20:59:16 UTC
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)
Comment 1 Paolo Carlini 2013-03-28 23:43:23 UTC
I see a sorry message thus the issue seems known.
Comment 2 rigaje 2013-03-29 00:45:23 UTC
(In reply to comment #1)
> I see a sorry message thus the issue seems known.

I agree. What confused me was that the feature is not unimplemented, it worked well for ordinary functions. I wonder what makes function templates a special exception in this case.
Comment 3 Jason Merrill 2013-04-01 21:22:40 UTC
Fixed for 4.8.1/4.9.