Detect always-invalid valptridx indexes

This commit is contained in:
Kp 2014-01-10 03:58:03 +00:00
parent f0aad4dcd6
commit 07a23cbaf2

View file

@ -49,6 +49,17 @@ protected:
DXX_INHERIT_CONSTRUCTORS(c##N##_t, N##_template_t<P const>) \
} \
#ifdef DXX_HAVE_BUILTIN_CONSTANT_P
#define DXX_VALPTRIDX_STATIC_CHECK(I,E,F,S) \
if (dxx_builtin_constant_p(I) && !(E)) { \
void F() __attribute_error(S); \
F(); \
}
#else
#define DXX_VALPTRIDX_STATIC_CHECK(I,E,F,S) \
#endif
#define DEFINE_VALPTRIDX_SUBTYPE(N,P,I,A) \
_DEFINE_VALPTRIDX_SUBTYPE_HEADER(N,I) \
{ \
@ -57,10 +68,12 @@ protected:
N##_template_t(pointer_type t) : \
base_type(t, t-A) \
{ \
DXX_VALPTRIDX_STATIC_CHECK(t, t, dxx_trap_constant_null_pointer, "NULL pointer used"); \
} \
N##_template_t(index_type s) : \
base_type(&A[s], s) \
{ \
DXX_VALPTRIDX_STATIC_CHECK(s, static_cast<std::size_t>(s) < A.size(), dxx_trap_constant_invalid_index, "invalid index used in array subscript"); \
} \
template <index_type i> \
N##_template_t(const P##_magic_constant_t<i> &) : \