From 8af7b8c13019a8aadeec28bf26da87e585e324cd Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Fri, 17 Mar 2017 13:08:07 +0300 Subject: [PATCH] Poisoned the C library identifiers --- test/test_macros.hpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/test/test_macros.hpp b/test/test_macros.hpp index 998264db82..28b2a32070 100644 --- a/test/test_macros.hpp +++ b/test/test_macros.hpp @@ -4,9 +4,44 @@ * Helps with cmake testing. * * @author James Goppert + * Pavel Kirienko */ #pragma once #include +#include // cmath has to be introduced BEFORE we poison the C library identifiers #define TEST(X) if(!(X)) { fprintf(stderr, "test failed on %s:%d\n", __FILE__, __LINE__); return -1;} + +/** + * This construct is needed to catch any unintended use of the C standard library. + * Feel free to extend the list of poisoned identifiers with as many C functions as possible. + * The current list was constructed by means of automated parsing of http://en.cppreference.com/w/c/numeric/math + */ +#ifdef __GNUC__ + +// float functions +# pragma GCC poison fabsf fmodf +# pragma GCC poison remainderf remquof fmaf fmaxf fminf fdimf fnanf expf +# pragma GCC poison exp2f expm1f logf log10f log2f log1pf powf sqrtf cbrtf +# pragma GCC poison hypotf sinf cosf tanf asinf acosf atanf atan2f sinhf +# pragma GCC poison coshf tanhf asinhf acoshf atanhf erff erfcf tgammaf +# pragma GCC poison lgammaf ceilf floorf truncf roundf nearbyintf rintf +# pragma GCC poison frexpf ldexpf modff scalbnf ilogbf logbf nextafterf +# pragma GCC poison copysignf + +// double functions +// this list is scarce because otherwise most functions from std:: would be also poisoned, which we don't want +# pragma GCC poison fabs + +// long double functions +# pragma GCC poison fabsl fabsl fabsl fmodl +# pragma GCC poison remainderl remquol fmal fmaxl fminl fdiml fnanl expl +# pragma GCC poison exp2l expm1l logl log10l log2l log1pl powl sqrtl cbrtl +# pragma GCC poison hypotl sinl cosl tanl asinl acosl atanl atan2l sinhl +# pragma GCC poison coshl tanhl asinhl acoshl atanhl erfl erfcl tgammal +# pragma GCC poison lgammal ceill floorl truncl roundl nearbyintl rintl +# pragma GCC poison frexpl ldexpl modfl scalbnl ilogbl logbl nextafterl +# pragma GCC poison copysignl + +#endif