diff --git a/src/Image.h b/src/Image.h index 6c171af4e..18dcd3b9b 100644 --- a/src/Image.h +++ b/src/Image.h @@ -80,12 +80,18 @@ template class Image: public AbstractImage { /** @brief Destructor */ ~Image() { delete[] _data; } - /** - * @brief Conversion to reference - * - * @todo GCC 4.8: don't allow this on rvalue-ref - */ - /*implicit*/ operator ImageReference() const; + /** @brief Conversion to reference */ + /*implicit*/ operator ImageReference() + #ifndef CORRADE_GCC47_COMPATIBILITY + const &; + #else + const; + #endif + + #ifndef CORRADE_GCC47_COMPATIBILITY + /** @overload */ + /*implicit*/ operator ImageReference() const && = delete; + #endif /** @brief %Image size */ typename DimensionTraits::VectorType size() const { return _size; } @@ -132,7 +138,13 @@ template inline Image& Image::op return *this; } -template inline Image::operator ImageReference() const { +template inline Image::operator ImageReference() +#ifndef CORRADE_GCC47_COMPATIBILITY +const & +#else +const +#endif +{ return ImageReference(AbstractImage::format(), AbstractImage::type(), _size, _data); } diff --git a/src/Test/ImageTest.cpp b/src/Test/ImageTest.cpp index 6948f9c8d..75849d5f7 100644 --- a/src/Test/ImageTest.cpp +++ b/src/Test/ImageTest.cpp @@ -71,13 +71,22 @@ void ImageTest::moveAssignment() { void ImageTest::toReference() { unsigned char* data = new unsigned char[3]; - Image2D a(ColorFormat::Red, ColorType::UnsignedByte, {1, 3}, data); + const Image2D a(ColorFormat::Red, ColorType::UnsignedByte, {1, 3}, data); ImageReference2D b = a; CORRADE_COMPARE(b.format(), ColorFormat::Red); CORRADE_COMPARE(b.type(), ColorType::UnsignedByte); CORRADE_COMPARE(b.size(), Vector2i(1, 3)); CORRADE_VERIFY(b.data() == data); + + CORRADE_VERIFY((std::is_convertible::value)); + { + #ifdef CORRADE_GCC47_COMPATIBILITY + CORRADE_EXPECT_FAIL("Rvalue references for *this are not supported in GCC < 4.8.1."); + #endif + CORRADE_VERIFY(!(std::is_convertible::value)); + CORRADE_VERIFY(!(std::is_convertible::value)); + } } }} diff --git a/src/Trade/ImageData.h b/src/Trade/ImageData.h index 098461302..e06f973f0 100644 --- a/src/Trade/ImageData.h +++ b/src/Trade/ImageData.h @@ -70,12 +70,18 @@ template class ImageData: public AbstractImage { /** @brief Destructor */ ~ImageData() { delete[] _data; } - /** - * @brief Conversion to reference - * - * @todo GCC 4.8: don't allow this on rvalue-ref - */ - /*implicit*/ operator ImageReference() const; + /** @brief Conversion to reference */ + /*implicit*/ operator ImageReference() + #ifndef CORRADE_GCC47_COMPATIBILITY + const &; + #else + const; + #endif + + #ifndef CORRADE_GCC47_COMPATIBILITY + /** @overload */ + /*implicit*/ operator ImageReference() const && = delete; + #endif /** @brief %Image size */ typename DimensionTraits::VectorType size() const { return _size; } @@ -110,7 +116,13 @@ template inline ImageData& ImageData inline ImageData::operator ImageReference() const { +template inline ImageData::operator ImageReference() +#ifndef CORRADE_GCC47_COMPATIBILITY +const & +#else +const +#endif +{ return ImageReference(AbstractImage::format(), AbstractImage::type(), _size, _data); } diff --git a/src/Trade/Test/ImageDataTest.cpp b/src/Trade/Test/ImageDataTest.cpp index bf1b9bb41..da3a7d39d 100644 --- a/src/Trade/Test/ImageDataTest.cpp +++ b/src/Trade/Test/ImageDataTest.cpp @@ -71,13 +71,22 @@ void ImageDataTest::moveAssignment() { void ImageDataTest::toReference() { unsigned char* data = new unsigned char[3]; - Trade::ImageData2D a(ColorFormat::Red, ColorType::UnsignedByte, {1, 3}, data); + const Trade::ImageData2D a(ColorFormat::Red, ColorType::UnsignedByte, {1, 3}, data); ImageReference2D b = a; CORRADE_COMPARE(b.format(), ColorFormat::Red); CORRADE_COMPARE(b.type(), ColorType::UnsignedByte); CORRADE_COMPARE(b.size(), Vector2i(1, 3)); CORRADE_COMPARE(b.data(), data); + + CORRADE_VERIFY((std::is_convertible::value)); + { + #ifdef CORRADE_GCC47_COMPATIBILITY + CORRADE_EXPECT_FAIL("Rvalue references for *this are not supported in GCC < 4.8.1."); + #endif + CORRADE_VERIFY(!(std::is_convertible::value)); + CORRADE_VERIFY(!(std::is_convertible::value)); + } } }}}