gcc 4.6 reclassified taking address of a temporary from warning to error (the C++ specification only allows lvalue or qualified-id as argument to operator &). The error appears in many places in the generated sources.
There seem to be two different cases:
- Unnecessary casts. E.g. in build/cpp/qt_gui/QAbstractTextDocumentLayout_shell.cpp are expressions like &(QTextInlineObject )item0 where item0 is of type QTextInlineObject anyway.
- Expressions of the form &qtd_from_QModelIndex(argument). This is most cases, e.g. in build/cpp/qt_gui/QAbstractProxyModel_shell.cpp. It is tricky, because it really is temporary, so it needs to be converted to lvalue to take address of it.
A correct fix I think would be defining a function template to promote an rvalue to lvalue and than pointer. In C++11 it should be doable with rvalue references, but without it's still possible with a const_cast:
template <typename T>
T *getPointer(const T &obj) {
return const_cast<T *>(&obj);
}
abusing the fact rvalues can be bound to const lvalue references. Alternatively the QModelIndexAccessor could get a method to return the pointer, because methods can be called on temporaries:
QModelIndexAccessor *QModelIndexAccessor::pointer() { return this }
which would not handle the other cases, but if it's possible to handle them by removing the unnecessary casts, it would avoid the need for const_cast.
A quick workaround is to add -fpermissive to compiler options when compiling with gcc until some other compiler decides this is illegal as well.