Re: [Interest] use of deleted function errors in QList / qarraydataops.h

2023-02-27 Thread Hamish Moffatt via Interest

On 28/2/23 12:00, Hamish Moffatt via Interest wrote:
Qt5's documentation (like Qt6's) does say "QVector's value type must 
be an assignable data type", so the mystery here is perhaps why our 
code works with Qt5. 



Even in Qt6, it compiles with other things in the struct that aren't 
assignable though, just not QVector.


struct T
{
int x = 0;
};

struct S
{
//const QVector v; // compiles if not const
const T t;
const int x = 0;
};

QVector pv;
pv.push_back({});



Hamish
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] use of deleted function errors in QList / qarraydataops.h

2023-02-27 Thread Hamish Moffatt via Interest

On 28/2/23 11:49, Thiago Macieira wrote:

On Monday, 27 February 2023 16:22:46 PST Hamish Moffatt via Interest wrote:

How and when would Qt5 show an error? We have the above code working and
in production, and I'm able resize, copy and change, force a detach -
operations where QVector would need to copy elements.

Ah, looks like it isn't going to. I expected the issue was that it didn't
happen in this test case because it never detached. If you're definitely
detaching, then this isn't the same issue.

The issue here is that you have a type that is copy/move constructible, but
cannot be copy/move assigned. That's usually a bad combination; the new QList/
QVector code uses move-assignment when moving elements in the overlapping part
of the list.

We could determine that your type is not move-assignable and use a different
strategy, but this isn't implemented right now. It might be less efficient; I
wouldn't know.



Qt5's documentation (like Qt6's) does say "QVector's value type must be 
an assignable data type", so the mystery here is perhaps why our code 
works with Qt5.



Thanks,

Hamish

___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] use of deleted function errors in QList / qarraydataops.h

2023-02-27 Thread Thiago Macieira
On Monday, 27 February 2023 16:22:46 PST Hamish Moffatt via Interest wrote:
> How and when would Qt5 show an error? We have the above code working and
> in production, and I'm able resize, copy and change, force a detach -
> operations where QVector would need to copy elements.

Ah, looks like it isn't going to. I expected the issue was that it didn't 
happen in this test case because it never detached. If you're definitely 
detaching, then this isn't the same issue.

The issue here is that you have a type that is copy/move constructible, but 
cannot be copy/move assigned. That's usually a bad combination; the new QList/
QVector code uses move-assignment when moving elements in the overlapping part 
of the list.

We could determine that your type is not move-assignable and use a different 
strategy, but this isn't implemented right now. It might be less efficient; I 
wouldn't know.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Cloud Software Architect - Intel DCAI Cloud Engineering


smime.p7s
Description: S/MIME cryptographic signature
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] use of deleted function errors in QList / qarraydataops.h

2023-02-27 Thread Hamish Moffatt via Interest

On 28/2/23 11:14, Thiago Macieira wrote:

On Monday, 27 February 2023 13:05:01 PST Hamish Moffatt via Interest wrote:

On 28/2/23 04:14, Thiago Macieira wrote:

On Sunday, 26 February 2023 23:24:43 PST Hamish Moffatt via Interest wrote:

Is there a solution?

Remove the const in:
   struct S
   {
   
   const QVector v; // compiles if not const
   
   };


If S is not copyable, then QVector can't copy it and QVector requires
copying all its elements.

May I ask why that is? Qt5 QVector and std::vector are both OK with the
above.

Qt 5 QVector is not ok with the above, it just hasn't produced an error *yet*.
All Qt main containers are implicitly-shared and therefore must be able to
copy their elements. Therefore, your elements must be copyable.

std::vector doesn't have this requirement. It is copyable if the element is
copyable, otherwise it isn't.

How and when would Qt5 show an error? We have the above code working and 
in production, and I'm able resize, copy and change, force a detach - 
operations where QVector would need to copy elements.



Hamish

___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] use of deleted function errors in QList / qarraydataops.h

2023-02-27 Thread Thiago Macieira
On Monday, 27 February 2023 13:05:01 PST Hamish Moffatt via Interest wrote:
> On 28/2/23 04:14, Thiago Macieira wrote:
> > On Sunday, 26 February 2023 23:24:43 PST Hamish Moffatt via Interest wrote:
> >> Is there a solution?
> > 
> > Remove the const in:
> >   struct S
> >   {
> >   
> >   const QVector v; // compiles if not const
> >   
> >   };
> > 
> > If S is not copyable, then QVector can't copy it and QVector requires
> > copying all its elements.
> 
> May I ask why that is? Qt5 QVector and std::vector are both OK with the
> above.

Qt 5 QVector is not ok with the above, it just hasn't produced an error *yet*. 
All Qt main containers are implicitly-shared and therefore must be able to 
copy their elements. Therefore, your elements must be copyable.

std::vector doesn't have this requirement. It is copyable if the element is 
copyable, otherwise it isn't.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Cloud Software Architect - Intel DCAI Cloud Engineering


smime.p7s
Description: S/MIME cryptographic signature
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] use of deleted function errors in QList / qarraydataops.h

2023-02-27 Thread Hamish Moffatt via Interest

On 28/2/23 04:14, Thiago Macieira wrote:

On Sunday, 26 February 2023 23:24:43 PST Hamish Moffatt via Interest wrote:

Is there a solution?

Remove the const in:

  struct S
  {
  const QVector v; // compiles if not const
  };

If S is not copyable, then QVector can't copy it and QVector requires copying
all its elements.


May I ask why that is? Qt5 QVector and std::vector are both OK with the 
above.



Hamish

___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] use of deleted function errors in QList / qarraydataops.h

2023-02-27 Thread Thiago Macieira
On Sunday, 26 February 2023 23:24:43 PST Hamish Moffatt via Interest wrote:
> Is there a solution?

Remove the const in:

 struct S
 {
 const QVector v; // compiles if not const
 };

If S is not copyable, then QVector can't copy it and QVector requires copying 
all its elements.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Cloud Software Architect - Intel DCAI Cloud Engineering


smime.p7s
Description: S/MIME cryptographic signature
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


[Interest] use of deleted function errors in QList / qarraydataops.h

2023-02-26 Thread Hamish Moffatt via Interest

I have some code which boils down to this:


#include 

void test()

{

    struct S

    {

        const QVector v; // compiles if not const

    };

    QVector> pv; // doesn't compile with this

    //std::vector> pv; // compiles with this

    pv.push_back(std::make_pair({}, {}));

}


This compiles in Qt 5.15.12, but not in 6.4.2.

The last line generates no less than 4 errors, resulting in pages and 
pages of output, but essentially:


../../dev/Qt6.4.2/6.4.2/gcc_64/include/QtCore/qarraydataops.h:472:29: error: use of deleted function 
‘std::pair& std::pair::operator=(const 
std::pair&)’
  472 | last[i] = std::move(last[i - 1]);
  | ^~~~
--
../../dev/Qt6.4.2/6.4.2/gcc_64/include/QtCore/qarraydataops.h:475:24: error: use of deleted function 
‘std::pair& std::pair::operator=(const 
std::pair&)’
  475 | *where = std::move(t);
  | ~~~^~
--
../../dev/Qt6.4.2/6.4.2/gcc_64/include/QtCore/qcontainertools_impl.h:132:18: error: use of deleted 
function ‘std::pair& std::pair::operator=(const std::pair&)’
  132 | *d_first = std::move_if_noexcept(*first);
  | ~^~~
--
../../dev/Qt6.4.2/6.4.2/gcc_64/include/QtCore/qcontainertools_impl.h:132:18: error: use of deleted 
function ‘std::pair& std::pair::operator=(const std::pair&)’


As per the comments, it compiles if the member variable in the inner 
struct is not const, or if I use a std::vector instead of QVector.


Is there a solution?

Full error text below.


Hamish




In file included from 
../../dev/Qt6.4.2/6.4.2/gcc_64/include/QtCore/qarraydatapointer.h:7,

 from ../../dev/Qt6.4.2/6.4.2/gcc_64/include/QtCore/qlist.h:8,

 from ../../dev/Qt6.4.2/6.4.2/gcc_64/include/QtCore/qvector.h:7,

 from ../../dev/Qt6.4.2/6.4.2/gcc_64/include/QtCore/QVector:1,

 from test.cc:1:

../../dev/Qt6.4.2/6.4.2/gcc_64/include/QtCore/qarraydataops.h: In instantiation of ‘void 
QtPrivate::QGenericArrayOps::Inserter::insertOne(qsizetype, T&&) [with T = 
std::pair; qsizetype = long long int]’:

../../dev/Qt6.4.2/6.4.2/gcc_64/include/QtCore/qarraydataops.h:557:37:   required from ‘void 
QtPrivate::QGenericArrayOps::emplace(qsizetype, Args&& ...) [with Args = 
{std::pair}; T = std::pair; qsizetype = long long 
int]’

../../dev/Qt6.4.2/6.4.2/gcc_64/include/QtCore/qlist.h:852:15:   required from ‘T& 
QList::emplaceBack(Args&& ...) [with Args = {std::pair}; T = 
std::pair; QList::reference = std::pair&]’

../../dev/Qt6.4.2/6.4.2/gcc_64/include/QtCore/qlist.h:440:24:   required from ‘void 
QList::append(QList::rvalue_ref) [with T = std::pair; 
QList::rvalue_ref = std::pair&&]’

../../dev/Qt6.4.2/6.4.2/gcc_64/include/QtCore/qlist.h:652:42:   required from ‘void 
QList::push_back(QList::rvalue_ref) [with T = std::pair; 
QList::rvalue_ref = std::pair&&]’

test.cc:13:43:   required from here

../../dev/Qt6.4.2/6.4.2/gcc_64/include/QtCore/qarraydataops.h:472:29: error: use of deleted function 
‘std::pair& std::pair::operator=(const 
std::pair&)’

  472 | last[i] = std::move(last[i - 1]);

  | ^~~~

In file included from /usr/include/c++/10/utility:70,

 from 
../../dev/Qt6.4.2/6.4.2/gcc_64/include/QtCore/qglobal.h:11,

 from ../../dev/Qt6.4.2/6.4.2/gcc_64/include/QtCore/qpair.h:7,

 from 
../../dev/Qt6.4.2/6.4.2/gcc_64/include/QtCore/qarraydata.h:8,

 from 
../../dev/Qt6.4.2/6.4.2/gcc_64/include/QtCore/qarraydataops.h:8,

 from 
../../dev/Qt6.4.2/6.4.2/gcc_64/include/QtCore/qarraydatapointer.h:7,

 from ../../dev/Qt6.4.2/6.4.2/gcc_64/include/QtCore/qlist.h:8,

 from ../../dev/Qt6.4.2/6.4.2/gcc_64/include/QtCore/qvector.h:7,

 from ../../dev/Qt6.4.2/6.4.2/gcc_64/include/QtCore/QVector:1,

 from test.cc:1:

/usr/include/c++/10/bits/stl_pair.h:211:12: note: ‘std::pair& 
std::pair::operator=(const std::pair&)’ is 
implicitly declared as deleted because ‘std::pair’ declares a move constructor or 
move assignment operator

  211 | struct pair

  |    ^~~~

In file included from 
../../dev/Qt6.4.2/6.4.2/gcc_64/include/QtCore/qarraydatapointer.h:7,

 from ../../dev/Qt6.4.2/6.4.2/gcc_64/include/QtCore/qlist.h:8,

 from ../../dev/Qt6.4.2/6.4.2/gcc_64/include/QtCore/qvector.h:7,

 from ../../dev/Qt6.4.2/6.4.2/gcc_64/include/QtCore/QVector:1,

 from test.cc:1:

../../dev/Qt6.4.2/6.4.2/gcc_64/include/QtCore/qarraydataops.h:475:24: error: use of deleted function 
‘std::pair& std::pair::operator=(const 
std::pair&)’

  475 | *where = std::move(t);

  | ~~~^~

In file included from