From 5730719a54e92e0816ef2b4217a2277907d67bcc Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jarkko=20P=C3=B6yry?= Date: Fri, 13 Feb 2015 13:00:34 -0800 Subject: [PATCH] Prevent incorrect usage of de::getSizedArrayElement. - Prevent usage without <..._LAST> template argument. - Preserve old usage as de::getArrayElement. Change-Id: I1ab7cf128ebe8b1805f2fc4ac062dc8f6cc7e859 --- framework/delibs/decpp/deDefs.hpp | 22 ++++++++++++++++++- .../gles31/functional/es31fCopyImageTests.cpp | 2 +- modules/glshared/glsBuiltinPrecisionTests.cpp | 6 ++--- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/framework/delibs/decpp/deDefs.hpp b/framework/delibs/decpp/deDefs.hpp index 88ba2f627..e07af19d6 100644 --- a/framework/delibs/decpp/deDefs.hpp +++ b/framework/delibs/decpp/deDefs.hpp @@ -71,9 +71,29 @@ template struct ArrayDeleter inline void operator() (T* ptr) const { delete[] ptr; } }; +template +struct EnableIf +{ +}; + + +template +struct EnableIf +{ + typedef T Type; +}; + //! Get an element of an array with a specified size. +template +const Elem& getSizedArrayElement (const Elem (&array)[Size], typename de::EnableIf::Type offset) +{ + DE_ASSERT(inBounds(offset, 0, Size)); + return array[offset]; +} + +//! Get an element of an array with a compile-time constant size. template -const Elem& getSizedArrayElement(const Elem (&array)[Size], int offset) +const Elem& getArrayElement (const Elem (&array)[Size], int offset) { DE_ASSERT(inBounds(offset, 0, Size)); return array[offset]; diff --git a/modules/gles31/functional/es31fCopyImageTests.cpp b/modules/gles31/functional/es31fCopyImageTests.cpp index 2700acefd..bb187b1ac 100644 --- a/modules/gles31/functional/es31fCopyImageTests.cpp +++ b/modules/gles31/functional/es31fCopyImageTests.cpp @@ -502,7 +502,7 @@ deUint32 mapFaceNdxToFace (int ndx) GL_TEXTURE_CUBE_MAP_NEGATIVE_Z }; - return de::getSizedArrayElement(cubeFaces, ndx); + return de::getSizedArrayElement<6>(cubeFaces, ndx); } deUint32 getFormatForInternalFormat (deUint32 format) diff --git a/modules/glshared/glsBuiltinPrecisionTests.cpp b/modules/glshared/glsBuiltinPrecisionTests.cpp index cb11004c8..eeef119c3 100644 --- a/modules/glshared/glsBuiltinPrecisionTests.cpp +++ b/modules/glshared/glsBuiltinPrecisionTests.cpp @@ -5191,9 +5191,9 @@ TestCaseGroup* createFuncGroup (const PrecisionTestContext& ctx, { const Precision precision = Precision(precNdx); const string precName (glu::getPrecisionName(precision)); - const FloatFormat& fmt = *de::getSizedArrayElement(ctx.formats, precNdx); - const FloatFormat& highpFmt = *de::getSizedArrayElement(ctx.formats, - glu::PRECISION_HIGHP); + const FloatFormat& fmt = *de::getSizedArrayElement(ctx.formats, precNdx); + const FloatFormat& highpFmt = *de::getSizedArrayElement(ctx.formats, + glu::PRECISION_HIGHP); for (size_t shaderNdx = 0; shaderNdx < ctx.shaderTypes.size(); ++shaderNdx) { -- 2.34.1