1*ac66081dSrillig /* $NetBSD: assert.h,v 1.26 2023/09/12 22:08:24 rillig Exp $ */ 24d2cbfceScgd 3e6b5ddd9Scgd /*- 4e6b5ddd9Scgd * Copyright (c) 1992, 1993 5e6b5ddd9Scgd * The Regents of the University of California. All rights reserved. 6e6b5ddd9Scgd * (c) UNIX System Laboratories, Inc. 7e6b5ddd9Scgd * All or some portions of this file are derived from material licensed 8e6b5ddd9Scgd * to the University of California by American Telephone and Telegraph 9e6b5ddd9Scgd * Co. or Unix System Laboratories, Inc. and are reproduced herein with 10e6b5ddd9Scgd * the permission of UNIX System Laboratories, Inc. 11e6b5ddd9Scgd * 12e6b5ddd9Scgd * Redistribution and use in source and binary forms, with or without 13e6b5ddd9Scgd * modification, are permitted provided that the following conditions 14e6b5ddd9Scgd * are met: 15e6b5ddd9Scgd * 1. Redistributions of source code must retain the above copyright 16e6b5ddd9Scgd * notice, this list of conditions and the following disclaimer. 17e6b5ddd9Scgd * 2. Redistributions in binary form must reproduce the above copyright 18e6b5ddd9Scgd * notice, this list of conditions and the following disclaimer in the 19e6b5ddd9Scgd * documentation and/or other materials provided with the distribution. 20039cc956Sagc * 3. Neither the name of the University nor the names of its contributors 21e6b5ddd9Scgd * may be used to endorse or promote products derived from this software 22e6b5ddd9Scgd * without specific prior written permission. 23e6b5ddd9Scgd * 24e6b5ddd9Scgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25e6b5ddd9Scgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26e6b5ddd9Scgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27e6b5ddd9Scgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28e6b5ddd9Scgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29e6b5ddd9Scgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30e6b5ddd9Scgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31e6b5ddd9Scgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32e6b5ddd9Scgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33e6b5ddd9Scgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34e6b5ddd9Scgd * SUCH DAMAGE. 35e6b5ddd9Scgd * 364d2cbfceScgd * @(#)assert.h 8.2 (Berkeley) 1/21/94 37e6b5ddd9Scgd */ 38e6b5ddd9Scgd 39e6b5ddd9Scgd /* 40e6b5ddd9Scgd * Unlike other ANSI header files, <assert.h> may usefully be included 41e6b5ddd9Scgd * multiple times, with and without NDEBUG defined. 42e6b5ddd9Scgd */ 43e6b5ddd9Scgd 44c3dba0b2Skleink #include <sys/cdefs.h> 4537a103a1Sbjh21 #include <sys/featuretest.h> 463e6c4846Schristos #include <sys/null.h> 47c3dba0b2Skleink 48e6b5ddd9Scgd #undef assert 49e6b5ddd9Scgd 50e6b5ddd9Scgd #ifdef NDEBUG 51c3dba0b2Skleink # define assert(e) (__static_cast(void,0)) 52e5571040Schristos #else /* !NDEBUG */ 53beec9356Skleink # if __STDC__ 54f02540ffSkleink # define assert(e) \ 55c3dba0b2Skleink ((e) ? __static_cast(void,0) : __assert13(__FILE__, __LINE__, \ 56f02540ffSkleink __assert_function__, #e)) 57e6b5ddd9Scgd # else /* PCC */ 58f02540ffSkleink # define assert(e) \ 59c3dba0b2Skleink ((e) ? __static_cast(void,0) : __assert13(__FILE__, __LINE__, \ 60f02540ffSkleink __assert_function__, "e")) 61beec9356Skleink # endif /* !__STDC__ */ 62e5571040Schristos #endif /* NDEBUG */ 63e6b5ddd9Scgd 6465047264Slukem #undef _DIAGASSERT 6565047264Slukem #if !defined(_DIAGNOSTIC) 66c3dba0b2Skleink # define _DIAGASSERT(e) (__static_cast(void,0)) 6765047264Slukem #else /* _DIAGNOSTIC */ 68beec9356Skleink # if __STDC__ 69f02540ffSkleink # define _DIAGASSERT(e) \ 70c3dba0b2Skleink ((e) ? __static_cast(void,0) : __diagassert13(__FILE__, __LINE__, \ 71f02540ffSkleink __assert_function__, #e)) 7265047264Slukem # else /* !__STDC__ */ 73f02540ffSkleink # define _DIAGASSERT(e) \ 74c3dba0b2Skleink ((e) ? __static_cast(void,0) : __diagassert13(__FILE__, __LINE__, \ 75f02540ffSkleink __assert_function__, "e")) 7665047264Slukem # endif 7765047264Slukem #endif /* _DIAGNOSTIC */ 7865047264Slukem 7965047264Slukem 80*ac66081dSrillig #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L 81f02540ffSkleink #define __assert_function__ __func__ 82f02540ffSkleink #elif __GNUC_PREREQ__(2, 6) 83f02540ffSkleink #define __assert_function__ __PRETTY_FUNCTION__ 84f02540ffSkleink #else 85c3dba0b2Skleink #define __assert_function__ (__static_cast(const void *,0)) 86f02540ffSkleink #endif 87f02540ffSkleink 88b87a6ffaSchristos #ifndef __ASSERT_DECLARED 89b87a6ffaSchristos #define __ASSERT_DECLARED 90e6b5ddd9Scgd __BEGIN_DECLS 91be47d2fcSjoerg __dead void __assert(const char *, int, const char *); 92be47d2fcSjoerg __dead void __assert13(const char *, int, const char *, const char *); 9319b7469aSperry void __diagassert(const char *, int, const char *); 9419b7469aSperry void __diagassert13(const char *, int, const char *, const char *); 95e6b5ddd9Scgd __END_DECLS 96b87a6ffaSchristos #endif /* __ASSERT_DECLARED */ 97ba27f5b7Skamil 98002b04a5Skamil #if defined(_ISOC11_SOURCE) || (__STDC_VERSION__ - 0) >= 201101L 993e0acd5aSkamil #ifndef static_assert 100ba27f5b7Skamil #define static_assert _Static_assert 101ba27f5b7Skamil #endif /* static_assert */ 102ba27f5b7Skamil #endif 103