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++/46696] New: Implicit copy constructor can't construct array of subtype with user-defined copy constructor.


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

           Summary: Implicit copy constructor can't construct array of
                    subtype with user-defined copy constructor.
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: yacwroy@gmail.com


Created attachment 22558
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=22558
Test source - erroneously fails to compile.

I think I may have hit a bug where an implicit copy constructor can't
construct an array of a subtype with a user-defined copy constructor.
I can't see any hits searching for "invalid array assignment" on the
bug repository.


Â12.8.28 states:
"A copy/move assignment operator that is defaulted and not defined as
deleted is implicitly defined when [...] or when it is explicitly
defaulted after its first declaration."

Â12.8.30 (implicitly-defined copy assignment) states:
"The implicitly-defined copy assignment operator for a non-union class
X performs memberwise copy assignment of its subobjects [...]
Each subobject is assigned in the manner appropriate to its type: [...]
-- if the subobject is an array, each element is assigned, in the
manner appropriate to the element type;"
I'm assuming that "the manner appropriate to the element type" means
use copy-assignment. At least, that's what seems to happens if the
main object's copy-assignment operator is implicitly defined.

Yet the above doesn't seem able to compile if:
- The main object contains an array of the subobject.
- The main object's copy-assignment operator IS explicitly defaulted
(Â12.8.28).
- The subobject's copy-assignment operator isn't implicitly or default defined.


TEST SOURCE (Attached):
1) I created the most trivial type (named SFoo) that contains a
non-default copy-assignment operator.
2) I created the most trivial type (named SBar) that contains:
  - an array of SFoo.
  - an explicitly defaulted copy-assignment operator.
3) I created a function that:
  - creates two copies of SBar.
  - assigns one copy to the other.

TEST:
I compiled using the -std=c++0x option.
GCC refuses to compile (11:8: error: invalid array assignment).
- If I remove the explicit defaulting of SBar's copy-assignment, it works.
- If I default SFoo's copy-assignment, it works.

SPECS:
GCC: 4.6.0 20101106 (experimental) (GCC)
  - Using Pedro LamarÃo's delegating constructors patch:
  - http://gcc.gnu.org/ml/gcc-patches/2007-04/msg00620.html
  - (I can't see this having any effect here).
TARGET: x86_64-unknown-linux-gnu
SYSTEM: Ubuntu(64) 10.4. Core2Duo(64).


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