From owner-svn-src-head@freebsd.org Thu Sep 7 17:51:36 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 9E72BE0554E; Thu, 7 Sep 2017 17:51:36 +0000 (UTC) (envelope-from theraven@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 54A7266959; Thu, 7 Sep 2017 17:51:36 +0000 (UTC) (envelope-from theraven@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v87HpZR7061667; Thu, 7 Sep 2017 17:51:35 GMT (envelope-from theraven@FreeBSD.org) Received: (from theraven@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v87HpZZS061666; Thu, 7 Sep 2017 17:51:35 GMT (envelope-from theraven@FreeBSD.org) Message-Id: <201709071751.v87HpZZS061666@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: theraven set sender to theraven@FreeBSD.org using -f From: David Chisnall Date: Thu, 7 Sep 2017 17:51:35 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r323277 - head/lib/libc/locale X-SVN-Group: head X-SVN-Commit-Author: theraven X-SVN-Commit-Paths: head/lib/libc/locale X-SVN-Commit-Revision: 323277 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Sep 2017 17:51:36 -0000 Author: theraven Date: Thu Sep 7 17:51:35 2017 New Revision: 323277 URL: https://svnweb.freebsd.org/changeset/base/323277 Log: 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. Modified: head/lib/libc/locale/xlocale_private.h Modified: head/lib/libc/locale/xlocale_private.h ============================================================================== --- head/lib/libc/locale/xlocale_private.h Thu Sep 7 17:20:47 2017 (r323276) +++ head/lib/libc/locale/xlocale_private.h Thu Sep 7 17:51:35 2017 (r323277) @@ -40,6 +40,14 @@ #include #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