From ac4933548d5c76c12ffebbf85831e729b918792d Mon Sep 17 00:00:00 2001 From: vlefevre Date: Thu, 4 Aug 2016 13:43:31 +0000 Subject: [tools/mpfrlint] Added a test detecting (unsafe) macros of the form: #define FOO { ... } The following form is preferred in most of the cases to avoid spurious null statements: #define FOO do { ... } while (0) git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@10725 280ebfd0-de03-0410-8827-d642c229c3f4 --- tools/mpfrlint | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'tools/mpfrlint') diff --git a/tools/mpfrlint b/tools/mpfrlint index f25d84389..497ce57ff 100755 --- a/tools/mpfrlint +++ b/tools/mpfrlint @@ -185,6 +185,24 @@ do }' $file done +# Macros of the form: +# #define FOO { ... } +# may be unsafe and could yield obscure failures where writing "FOO;" as +# this is here a block followed by a null statement. The following form +# is preferred in most of the cases: +# #define FOO do { ... } while (0) +# so that "FOO;" is a single statement. +for file in $srctests +do + err-if-output "Missing 'do ... while (0)'" perl -e ' + while (<>) { + my $s = $_; + while ($s =~ s/\\\n//) { $s .= <> } + $s =~ /^#\s*define\s+\w+(\([^)]*\))?\s*{/ + and $s =~ tr/ \t/ /s, print "$ARGV: $s"; + }' $file +done + # Do not use snprintf as it is not available in ISO C90. # Even on platforms where it is available, the prototype # may not be included (e.g. with gcc -ansi), so that the -- cgit v1.2.1