Document some invariants for the XLC_ enum.

These can't be reordered without breaking other code.  Document that and add
some static asserts to ensure that anyone who tries gets build failures.
This commit is contained in:
David Chisnall 2017-09-07 17:51:35 +00:00
parent e881ec1646
commit c0cd38223c
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=323277

View File

@ -40,6 +40,14 @@
#include <machine/atomic.h>
#include "setlocale.h"
/**
* The XLC_ values are indexes into the components array. They are defined in
* the same order as the LC_ values in locale.h, but without the LC_ALL zero
* value. Translating from LC_X to XLC_X is done by subtracting one.
*
* Any reordering of this enum should ensure that these invariants are not
* violated.
*/
enum {
XLC_COLLATE = 0,
XLC_CTYPE,
@ -50,6 +58,19 @@ enum {
XLC_LAST
};
_Static_assert(XLC_LAST - XLC_COLLATE == 6, "XLC values should be contiguous");
_Static_assert(XLC_COLLATE == LC_COLLATE - 1,
"XLC_COLLATE doesn't match the LC_COLLATE value.");
_Static_assert(XLC_CTYPE == LC_CTYPE - 1,
"XLC_CTYPE doesn't match the LC_CTYPE value.");
_Static_assert(XLC_MONETARY == LC_MONETARY - 1,
"XLC_MONETARY doesn't match the LC_MONETARY value.");
_Static_assert(XLC_NUMERIC == LC_NUMERIC - 1,
"XLC_NUMERIC doesn't match the LC_NUMERIC value.");
_Static_assert(XLC_TIME == LC_TIME - 1,
"XLC_TIME doesn't match the LC_TIME value.");
_Static_assert(XLC_MESSAGES == LC_MESSAGES - 1,
"XLC_MESSAGES doesn't match the LC_MESSAGES value.");
/**
* Header used for objects that are reference counted. Objects may optionally