Enable strong-typed DE_LENGTH_OF_ARRAY for every compiler
authorRicardo Garcia <rgarcia@igalia.com>
Mon, 24 Jun 2019 09:22:56 +0000 (11:22 +0200)
committerAlexander Galazin <Alexander.Galazin@arm.com>
Thu, 4 Jul 2019 09:16:02 +0000 (05:16 -0400)
The C++ strong-typed version of DE_LENGTH_OF_ARRAY should work with
every C++ compiler. This commit removes the restriction of being used
only with the Microsoft compiler.

Components: Framework
VK-GL-CTS issue: 1848

Change-Id: Id28c02ab4dfecefa84093578afca0da50b0bdd65

framework/delibs/debase/deDefs.h

index bff057f..4edc5e8 100644 (file)
@@ -255,7 +255,10 @@ typedef void (*deFunctionPtr) (void);
 /*#define DE_VALGRIND_BUILD*/
 
 /** Length of array. C++ version does compile time check that passed value is an array reference. */
-#if defined(__cplusplus) && (DE_COMPILER == DE_COMPILER_MSC)
+#if defined(__cplusplus)
+       // deArraySizeHelper is a function that receives a reference to an array of N elements of type T and returns a reference to an
+       // array of N chars. This forces the compiler to check the argument is an actual array and not some other type implementing
+       // operator[]. The actual function is never defined anywhere, but taking the sizeof() of the result is allowed and equal to N.
        template <typename T, size_t N> char (&deArraySizeHelper(T (&array)[N]))[N];
 #      define DE_LENGTH_OF_ARRAY(ARRAY) ((int)(sizeof(deArraySizeHelper(ARRAY))))
 #else