Browse Source

GCC 4.5 compatibility: various constexpr issues.

Vladimír Vondruš 13 years ago
parent
commit
5ad38775b0
  1. 91
      src/AbstractShaderProgram.h
  2. 7
      src/Math/Algorithms/Svd.h
  3. 6
      src/MeshTools/Test/TransformTest.cpp
  4. 9
      src/Test/SwizzleTest.cpp

91
src/AbstractShaderProgram.h

@ -1145,19 +1145,39 @@ template<std::size_t cols> struct SizedVectorAttribute {
}; };
template<> struct SizedAttribute<1, 1>: SizedVectorAttribute<1> { template<> struct SizedAttribute<1, 1>: SizedVectorAttribute<1> {
enum class Components: GLint { One = 1 }; enum class Components: GLint { One = 1 };
constexpr static Components DefaultComponents = Components::One; #ifndef CORRADE_GCC45_COMPATIBILITY
constexpr static
#else
static const
#endif
Components DefaultComponents = Components::One;
}; };
template<> struct SizedAttribute<1, 2>: SizedVectorAttribute<1> { template<> struct SizedAttribute<1, 2>: SizedVectorAttribute<1> {
enum class Components: GLint { One = 1, Two = 2 }; enum class Components: GLint { One = 1, Two = 2 };
constexpr static Components DefaultComponents = Components::Two; #ifndef CORRADE_GCC45_COMPATIBILITY
constexpr static
#else
static const
#endif
Components DefaultComponents = Components::Two;
}; };
template<> struct SizedAttribute<1, 3>: SizedVectorAttribute<1> { template<> struct SizedAttribute<1, 3>: SizedVectorAttribute<1> {
enum class Components: GLint { One = 1, Two = 2, Three = 3 }; enum class Components: GLint { One = 1, Two = 2, Three = 3 };
constexpr static Components DefaultComponents = Components::Three; #ifndef CORRADE_GCC45_COMPATIBILITY
constexpr static
#else
static const
#endif
Components DefaultComponents = Components::Three;
}; };
template<> struct SizedAttribute<1, 4>: SizedVectorAttribute<1> { template<> struct SizedAttribute<1, 4>: SizedVectorAttribute<1> {
enum class Components: GLint { One = 1, Two = 2, Three = 3, Four = 4 }; enum class Components: GLint { One = 1, Two = 2, Three = 3, Four = 4 };
constexpr static Components DefaultComponents = Components::Four; #ifndef CORRADE_GCC45_COMPATIBILITY
constexpr static
#else
static const
#endif
Components DefaultComponents = Components::Four;
}; };
Debug MAGNUM_EXPORT operator<<(Debug debug, SizedAttribute<1, 1>::Components value); Debug MAGNUM_EXPORT operator<<(Debug debug, SizedAttribute<1, 1>::Components value);
Debug MAGNUM_EXPORT operator<<(Debug debug, SizedAttribute<1, 2>::Components value); Debug MAGNUM_EXPORT operator<<(Debug debug, SizedAttribute<1, 2>::Components value);
@ -1168,15 +1188,30 @@ Debug MAGNUM_EXPORT operator<<(Debug debug, SizedAttribute<1, 4>::Components val
template<std::size_t rows> struct SizedMatrixAttribute; template<std::size_t rows> struct SizedMatrixAttribute;
template<> struct SizedMatrixAttribute<2> { template<> struct SizedMatrixAttribute<2> {
enum class Components: GLint { Two = 2 }; enum class Components: GLint { Two = 2 };
constexpr static Components DefaultComponents = Components::Two; #ifndef CORRADE_GCC45_COMPATIBILITY
constexpr static
#else
static const
#endif
Components DefaultComponents = Components::Two;
}; };
template<> struct SizedMatrixAttribute<3> { template<> struct SizedMatrixAttribute<3> {
enum class Components: GLint { Three = 3 }; enum class Components: GLint { Three = 3 };
constexpr static Components DefaultComponents = Components::Three; #ifndef CORRADE_GCC45_COMPATIBILITY
constexpr static
#else
static const
#endif
Components DefaultComponents = Components::Three;
}; };
template<> struct SizedMatrixAttribute<4> { template<> struct SizedMatrixAttribute<4> {
enum class Components: GLint { Four = 4 }; enum class Components: GLint { Four = 4 };
constexpr static Components DefaultComponents = Components::Four; #ifndef CORRADE_GCC45_COMPATIBILITY
constexpr static
#else
static const
#endif
Components DefaultComponents = Components::Four;
}; };
Debug MAGNUM_EXPORT operator<<(Debug debug, SizedMatrixAttribute<2>::Components value); Debug MAGNUM_EXPORT operator<<(Debug debug, SizedMatrixAttribute<2>::Components value);
Debug MAGNUM_EXPORT operator<<(Debug debug, SizedMatrixAttribute<3>::Components value); Debug MAGNUM_EXPORT operator<<(Debug debug, SizedMatrixAttribute<3>::Components value);
@ -1219,7 +1254,12 @@ struct FloatAttribute {
Double = GL_DOUBLE Double = GL_DOUBLE
#endif #endif
}; };
constexpr static DataType DefaultDataType = DataType::Float; #ifndef CORRADE_GCC45_COMPATIBILITY
constexpr static
#else
static const
#endif
DataType DefaultDataType = DataType::Float;
enum class DataOption: UnsignedByte { enum class DataOption: UnsignedByte {
Normalized = 1 << 0 Normalized = 1 << 0
@ -1246,7 +1286,12 @@ struct IntAttribute {
UnsignedInt = GL_UNSIGNED_INT, UnsignedInt = GL_UNSIGNED_INT,
Int = GL_INT Int = GL_INT
}; };
constexpr static DataType DefaultDataType = DataType::Int; #ifndef CORRADE_GCC45_COMPATIBILITY
constexpr static
#else
static const
#endif
DataType DefaultDataType = DataType::Int;
enum class DataOption: UnsignedByte {}; enum class DataOption: UnsignedByte {};
typedef Corrade::Containers::EnumSet<DataOption, UnsignedByte> DataOptions; typedef Corrade::Containers::EnumSet<DataOption, UnsignedByte> DataOptions;
@ -1261,7 +1306,12 @@ struct UnsignedIntAttribute {
typedef UnsignedInt Type; typedef UnsignedInt Type;
typedef IntAttribute::DataType DataType; typedef IntAttribute::DataType DataType;
constexpr static DataType DefaultDataType = DataType::UnsignedInt; #ifndef CORRADE_GCC45_COMPATIBILITY
constexpr static
#else
static const
#endif
DataType DefaultDataType = DataType::UnsignedInt;
typedef IntAttribute::DataOption DataOption; typedef IntAttribute::DataOption DataOption;
typedef Corrade::Containers::EnumSet<DataOption, UnsignedByte> DataOptions; typedef Corrade::Containers::EnumSet<DataOption, UnsignedByte> DataOptions;
@ -1280,7 +1330,12 @@ struct DoubleAttribute {
enum class DataType: GLenum { enum class DataType: GLenum {
Double = GL_DOUBLE Double = GL_DOUBLE
}; };
constexpr static DataType DefaultDataType = DataType::Double; #ifndef CORRADE_GCC45_COMPATIBILITY
constexpr static
#else
static const
#endif
DataType DefaultDataType = DataType::Double;
enum class DataOption: UnsignedByte {}; enum class DataOption: UnsignedByte {};
typedef Corrade::Containers::EnumSet<DataOption, UnsignedByte> DataOptions; typedef Corrade::Containers::EnumSet<DataOption, UnsignedByte> DataOptions;
@ -1305,7 +1360,12 @@ template<> struct Attribute<Math::Vector<4, Float>> {
BGRA = GL_BGRA BGRA = GL_BGRA
#endif #endif
}; };
constexpr static Components DefaultComponents = Components::Four; #ifndef CORRADE_GCC45_COMPATIBILITY
constexpr static
#else
static const
#endif
Components DefaultComponents = Components::Four;
enum class DataType: GLenum { enum class DataType: GLenum {
UnsignedByte = GL_UNSIGNED_BYTE, UnsignedByte = GL_UNSIGNED_BYTE,
@ -1330,7 +1390,12 @@ template<> struct Attribute<Math::Vector<4, Float>> {
Int2101010Rev = GL_INT_2_10_10_10_REV Int2101010Rev = GL_INT_2_10_10_10_REV
#endif #endif
}; };
constexpr static DataType DefaultDataType = DataType::Float; #ifndef CORRADE_GCC45_COMPATIBILITY
constexpr static
#else
static const
#endif
DataType DefaultDataType = DataType::Float;
enum class DataOption: UnsignedByte { enum class DataOption: UnsignedByte {
Normalized = 1 << 0 Normalized = 1 << 0

7
src/Math/Algorithms/Svd.h

@ -96,9 +96,14 @@ decomposition and least squares solutions"*.
/* The matrix is passed by value because it is changed inside */ /* The matrix is passed by value because it is changed inside */
template<std::size_t cols, std::size_t rows, class T> std::tuple<RectangularMatrix<cols, rows, T>, Vector<cols, T>, Matrix<cols, T>> svd(RectangularMatrix<cols, rows, T> m) { template<std::size_t cols, std::size_t rows, class T> std::tuple<RectangularMatrix<cols, rows, T>, Vector<cols, T>, Matrix<cols, T>> svd(RectangularMatrix<cols, rows, T> m) {
static_assert(rows >= cols, "Unsupported matrix aspect ratio"); static_assert(rows >= cols, "Unsupported matrix aspect ratio");
static_assert(T(1)+TypeTraits<T>::epsilon() > T(1), "Epsilon too small");
constexpr T tol = Implementation::smallestDelta<T>()/TypeTraits<T>::epsilon(); constexpr T tol = Implementation::smallestDelta<T>()/TypeTraits<T>::epsilon();
#ifndef CORRADE_GCC45_COMPATIBILITY
static_assert(T(1)+TypeTraits<T>::epsilon() > T(1), "Epsilon too small");
static_assert(tol > T(0), "Tol too small"); static_assert(tol > T(0), "Tol too small");
#else
CORRADE_ASSERT(T(1)+TypeTraits<T>::epsilon() > T(1), "Epsilon too small", {});
CORRADE_ASSERT(tol > T(0), "Tol too small", {});
#endif
constexpr std::size_t maxIterations = 50; constexpr std::size_t maxIterations = 50;
Matrix<cols, T> v(Matrix<cols, T>::Zero); Matrix<cols, T> v(Matrix<cols, T>::Zero);

6
src/MeshTools/Test/TransformTest.cpp

@ -50,8 +50,8 @@ TransformTest::TransformTest() {
&TransformTest::transformPoints3D}); &TransformTest::transformPoints3D});
} }
/* GCC < 4.7 doesn't like constexpr here, don't know why */ /** @bug GCC < 4.7 doesn't like constexpr here, don't know why */
#ifdef CORRADE_GCC46_COMPATIBILITY #if defined(CORRADE_GCC46_COMPATIBILITY) && !defined(CORRADE_GCC45_COMPATIBILITY)
#define constexpr const #define constexpr const
#endif #endif
@ -85,7 +85,7 @@ constexpr static std::array<Vector3, 2> points3DRotatedTranslated{{
{15.0f, 1.5f, 1.5f} {15.0f, 1.5f, 1.5f}
}}; }};
#ifdef CORRADE_GCC46_COMPATIBILITY #if defined(CORRADE_GCC46_COMPATIBILITY) && !defined(CORRADE_GCC45_COMPATIBILITY)
#undef constexpr #undef constexpr
#endif #endif

9
src/Test/SwizzleTest.cpp

@ -53,6 +53,11 @@ void SwizzleTest::type() {
constexpr Color3<Float> origColor3; constexpr Color3<Float> origColor3;
constexpr Color4<Double> origColor4; constexpr Color4<Double> origColor4;
/* decltype(a) is not const because a is not constexpr under GCC <= 4.5 */
#ifdef CORRADE_GCC45_COMPATIBILITY
#define const
#endif
constexpr auto a = swizzle<'y', 'a'>(orig); constexpr auto a = swizzle<'y', 'a'>(orig);
CORRADE_VERIFY((std::is_same<decltype(a), const Vector2i>::value)); CORRADE_VERIFY((std::is_same<decltype(a), const Vector2i>::value));
@ -73,6 +78,10 @@ void SwizzleTest::type() {
constexpr auto g = swizzle<'y', 'a', 'y', 'x'>(origColor4); constexpr auto g = swizzle<'y', 'a', 'y', 'x'>(origColor4);
CORRADE_VERIFY((std::is_same<decltype(g), const Color4<Double>>::value)); CORRADE_VERIFY((std::is_same<decltype(g), const Color4<Double>>::value));
#ifdef CORRADE_GCC45_COMPATIBILITY
#undef const
#endif
} }
void SwizzleTest::defaultType() { void SwizzleTest::defaultType() {

Loading…
Cancel
Save