diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2020-06-09 00:57:05 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2020-06-09 00:57:05 +0000 |
commit | 49b578c61265818a86648908900046cd65188ff6 (patch) | |
tree | 4e8129e7b13c3f371921315af394297f110bf21c | |
parent | 28da1c273265520eb017a779bbe9ccbe74819a25 (diff) | |
download | mpfr-49b578c61265818a86648908900046cd65188ff6.tar.gz |
Removed MPFR_DECL_STATIC_ASSERT macro as it was buggy, unused, rather
useless, and it had drawbacks. Details:
* In src/mpfr-sassert.h, the default definition of this macro in the
MPFR_USE_STATIC_ASSERT case ended with a spurious ";". Since this
macro was unused, this wasn't noticeable... except in the configure
test for static assertions, which failed in some cases (e.g. with
CFLAGS="-std=c99 -pedantic-errors -Wno-error=overlength-strings")
for this reason, which had the effect to let MPFR_USE_STATIC_ASSERT
undefined, while static assertions were actually working.
* Still in src/mpfr-sassert.h, but when MPFR_USE_STATIC_ASSERT is not
defined, the MPFR_DECL_STATIC_ASSERT(c) expanded to nothing, which
would yield invalid code as
MPFR_DECL_STATIC_ASSERT(some_assertion);
would yield an extra ";" (about the same issue as above). Given
the fact that the portable MPFR_USE_STATIC_ASSERT code does not
work with this compiler, it is not clear whether this is fixable
in a completely reliable way.
* MPFR_DECL_STATIC_ASSERT can be replaced by MPFR_STAT_STATIC_ASSERT
after moving it to the statement section of a function, with almost
no drawbacks (just a bit readability in some cases?).
* When MPFR_USE_STATIC_ASSERT is not defined, MPFR_STAT_STATIC_ASSERT
will check the assertion at run time (for free, since the result is
known at compile time), while MPFR_DECL_STATIC_ASSERT would not be
able to do anything useful.
Changes:
* acinclude.m4: removed the test of MPFR_DECL_STATIC_ASSERT.
* src/mpfr-sassert.h: removed MPFR_DECL_STATIC_ASSERT definitions.
* tune/tuneup.c: removed MPFR_DECL_STATIC_ASSERT redefinition.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@13947 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r-- | acinclude.m4 | 2 | ||||
-rw-r--r-- | src/mpfr-sassert.h | 9 | ||||
-rw-r--r-- | tune/tuneup.c | 2 |
3 files changed, 1 insertions, 12 deletions
diff --git a/acinclude.m4 b/acinclude.m4 index 4ae14ab84..8f34fbc59 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -837,10 +837,8 @@ AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ #include "mpfr-sassert.h" /* Test if Static Assertions work */ -MPFR_DECL_STATIC_ASSERT(sizeof(char) <= sizeof(int)); int main (void) { - MPFR_DECL_STATIC_ASSERT(sizeof(int) <= sizeof(long)); int x; (void) (x = 1); /* cast to void: avoid a warning, at least with GCC */ /* Test of the macro after a declaraction and a statement. */ diff --git a/src/mpfr-sassert.h b/src/mpfr-sassert.h index c33b982ac..1c988f28f 100644 --- a/src/mpfr-sassert.h +++ b/src/mpfr-sassert.h @@ -27,8 +27,6 @@ https://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., /* How to use: =========== - MPFR_DECL_STATIC_ASSERT: - + to check a condition at compile time within the declaration section. MPFR_STAT_STATIC_ASSERT: + to check a condition at compile time within the statement section. @@ -43,13 +41,12 @@ https://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., /* C11 version */ # if defined (__STDC_VERSION__) # if (__STDC_VERSION__ >= 201112L) -# define MPFR_DECL_STATIC_ASSERT(c) _Static_assert((c), #c ) # define MPFR_STAT_STATIC_ASSERT(c) _Static_assert((c), #c ) # endif # endif /* Default version which should be compatible with nearly all compilers */ -# if !defined(MPFR_DECL_STATIC_ASSERT) +# if !defined(MPFR_STAT_STATIC_ASSERT) # if __MPFR_GNUC(4,8) /* Get rid of annoying warnings "typedef '...' locally defined but not used" (new in GCC 4.8). Thanks to Jonathan Wakely for this solution: @@ -64,15 +61,11 @@ https://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., typedef enum { MPFR_ASSERT_CAT(MPFR_STATIC_ASSERT_CONST_,__LINE__) = !(c) } \ MPFR_ASSERT_CAT(MPFR_ASSERT_,__LINE__)[!!(c) ? 1 : -1] \ MPFR_TYPEDEF_UNUSED; } while (0) -# define MPFR_DECL_STATIC_ASSERT(c) \ - typedef enum { MPFR_ASSERT_CAT(MPFR_STATIC_ASSERT_CONST_,__LINE__) = !(c) } \ - MPFR_ASSERT_CAT(MPFR_ASSERT_,__LINE__)[!!(c) ? 1 : -1]; # endif #else /* No support: default to classic assertions */ -# define MPFR_DECL_STATIC_ASSERT(c) /* Nothing */ # define MPFR_STAT_STATIC_ASSERT(c) MPFR_ASSERTN(c) #endif diff --git a/tune/tuneup.c b/tune/tuneup.c index 08cf151e3..2d783f598 100644 --- a/tune/tuneup.c +++ b/tune/tuneup.c @@ -31,9 +31,7 @@ https://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., #include "speed.h" /* Undefine static assertion system */ -#undef MPFR_DECL_STATIC_ASSERT #undef MPFR_STAT_STATIC_ASSERT -#define MPFR_DECL_STATIC_ASSERT(a) MPFR_ASSERTN(a) #define MPFR_STAT_STATIC_ASSERT(a) MPFR_ASSERTN(a) int verbose; |