This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/77840] List-initialization and copy-constructor


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77840

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Wolfgang Roehrl from comment #0)
> Hi,
> I would like to post a bug report for the GNU C/C++ compiler 6.1.1.
> We use the compiler to generate code for a PowerPC processor.
> Invokation line for the GNU C compiler:
> 
> ccppc -c -x c -std=gnu11 -Wall -Werror -g -mcpu=e6500 -m32
>       -maltivec -mvrsave -ftls-model=local-exec -msdata=sysv
>       -fno-common -fno-openmp -mbig -mmultiple -mno-string -misel
>       -mstrict-align -fverbose-asm -G 8 -O3
>       -I<some include paths>
>       -D<some #define's>
>       X.C -oX.O
> 
> 
> // file X.C
> 
> struct X
> {
>     X (int);
>     X (const X&) = delete;
> };
> 
> X arrX = { 1, 2, 3 };

I assume you meant arrX[] here?


> The compiler rejects this program because the copy constructor is
> deleted. But according to the C++11 standard this initialization
> should not involve a copy/move constructor (cf. 12.6.1/2).

I don't think that's correct. The code is roughly equivalent to:

  X arrX[] = { X(1), X(2), X(3) };

and that requires a copy constructor to initialize the array elements from the
X(1), X(2), X(3) temporaries.

> By the way, the compiler accepts a slighty different programm:
> 
> // file X.C
> 
> struct X
> {
>     X (int);
>     X (const X&) = delete;
> };
> 
> 
> X arrX[] = { {1}, {2}, {3} };

This is valid. In this code each X in the array is direct-list-initialized from
the {1} initializer, with no temporaries to be copied.

In other words, in the first example initialization of each element is
equivalent to

  X x = 1;

and in the second is equivalent to:

  X x{1};

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]