From add989703e694f7719e015cc12717d9953de0322 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 17 Nov 2013 22:34:23 +0100 Subject: [PATCH] Math: don't allow *::data() to be called on rvalues. There are more cases that should be fixed, but this is the most problematic one, as this might look completely innocent: Vector2 a, b; float* c = (a + b).data(); Unlike this, which looks suspicious: Vector2& c = a + b; --- src/Math/RectangularMatrix.h | 16 ++++++++++++++-- src/Math/Vector.h | 16 ++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/Math/RectangularMatrix.h b/src/Math/RectangularMatrix.h index cbb0a685f..89b365c56 100644 --- a/src/Math/RectangularMatrix.h +++ b/src/Math/RectangularMatrix.h @@ -164,8 +164,20 @@ template class RectangularMatrix { * * @see operator[] */ - T* data() { return _data[0].data(); } - constexpr const T* data() const { return _data[0].data(); } /**< @overload */ + T* data() + #ifndef CORRADE_GCC47_COMPATIBILITY + & + #endif + { return _data[0].data(); } + + /** @overload */ + constexpr const T* data() + #ifndef CORRADE_GCC47_COMPATIBILITY + const & + #else + const + #endif + { return _data[0].data(); } /** * @brief %Matrix column diff --git a/src/Math/Vector.h b/src/Math/Vector.h index 645b1b256..de6c77881 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -184,8 +184,20 @@ template class Vector { * * @see operator[]() */ - T* data() { return _data; } - constexpr const T* data() const { return _data; } /**< @overload */ + T* data() + #ifndef CORRADE_GCC47_COMPATIBILITY + & + #endif + { return _data; } + + /** @overload */ + constexpr const T* data() + #ifndef CORRADE_GCC47_COMPATIBILITY + const & + #else + const + #endif + { return _data; } /** * @brief Value at given position