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

            Bug ID: 91499
           Summary: Compile error when trying to aggregate-initialize a
                    member array of non-movable objects with virtual
                    functions
           Product: gcc
           Version: 9.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: l2m at ukr dot net
  Target Milestone: ---

Created attachment 46733
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=46733&action=edit
Output of "gcc -v" and the compilation error

This bug report is based on the stackoverflow discussion that can be found
here:
https://stackoverflow.com/questions/57559634/initialization-of-an-array-of-non-moveable-objects-why-does-such-code-fail-to-c

Here's the code that fails to compile on GCC:


class Test // non-copyable and non-movable class with virtual functions
{
public:
    Test() = delete;

    Test(const Test&) = delete;
    Test(Test&&) = delete;
    Test& operator=(const Test&) = delete;
    Test& operator=(Test&&) = delete;

    Test(int a, int b) : a_(a), b_(b) {}
    virtual ~Test() {}

    int a_;
    int b_;
};

//----------------

class B
{
public:
/*(1)*/ B() : test_{{1, 2}, {3, 4}} {} // Does not compile on GCC

private:
        Test test_[2];
};

//---------------- 

int main()
{
    B b;
    Test test[2] = {{1, 2}, {3, 4}}; // Successfully compiles
}


GCC 9.2 outputs:

<source>: In constructor 'B::B()':
<source>:23:35: error: use of deleted function 'Test::Test(Test&&)'
   23 | /*(1)*/ B() : test_{{1, 2}, {3, 4}} {} // Does not compile on GCC
      |                                   ^
<source>:7:5: note: declared here
    7 |     Test(Test&&) = delete;
      |     ^~~~

Other related information (the system type, the options given when GCC was
configured/built, the complete command line that triggers the bug, the compiler
output) is contained in the attached text file. Basically, this output was
taken from the https://godbolt.org/ online compiler. But all other compilers
that I've tried give the same error.
A preprocessed file (*.i*) is NOT included because I have "reduced the testcase
to a small file that doesn't include any other file" (item "ii" from Detailed
bug reporting instructions).

As explained by user L. F. on stackoverflow, this code is expected to be
compiled successfully without requiring a move constructor.

Reply via email to