Browse Source

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;
pull/34/head
Vladimír Vondruš 13 years ago
parent
commit
add989703e
  1. 16
      src/Math/RectangularMatrix.h
  2. 16
      src/Math/Vector.h

16
src/Math/RectangularMatrix.h

@ -164,8 +164,20 @@ template<std::size_t cols, std::size_t rows, class T> class RectangularMatrix {
* *
* @see operator[] * @see operator[]
*/ */
T* data() { return _data[0].data(); } T* data()
constexpr const T* data() const { return _data[0].data(); } /**< @overload */ #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 * @brief %Matrix column

16
src/Math/Vector.h

@ -184,8 +184,20 @@ template<std::size_t size, class T> class Vector {
* *
* @see operator[]() * @see operator[]()
*/ */
T* data() { return _data; } T* data()
constexpr const T* data() const { return _data; } /**< @overload */ #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 * @brief Value at given position

Loading…
Cancel
Save