From: Paul Eggert Date: Fri, 24 Feb 2012 21:52:45 +0000 (-0800) Subject: stdnoreturn: new module X-Git-Tag: v0.1~1138 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=9a9dd2c085a29b7837437dd8fbf3ccc96d4e71df;p=gnulib.git stdnoreturn: new module This implements a replacement for C11's . * doc/gnulib.texi (Header File Substitutes): Add stdnoreturn. * doc/posix-headers/stdnoreturn.texi, lib/stdnoreturn.in.h: * m4/stdnoreturn.m4, modules/stdnoreturn, modules/stdnoreturn-tests: * tests/test-stdnoreturn.c: New files. --- diff --git a/ChangeLog b/ChangeLog index 53680d83c..c7a6e1071 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2012-02-24 Paul Eggert + + stdnoreturn: new module + This implements a replacement for C11's . + * doc/gnulib.texi (Header File Substitutes): Add stdnoreturn. + * doc/posix-headers/stdnoreturn.texi, lib/stdnoreturn.in.h: + * m4/stdnoreturn.m4, modules/stdnoreturn, modules/stdnoreturn-tests: + * tests/test-stdnoreturn.c: New files. + 2012-02-24 Stanislav Brabec (tiny change) regex: fix false multibyte matches in some regular expressions diff --git a/doc/gnulib.texi b/doc/gnulib.texi index 1581942d1..cd9586475 100644 --- a/doc/gnulib.texi +++ b/doc/gnulib.texi @@ -1194,6 +1194,7 @@ which (known) portability problems are not worked around by Gnulib. * stdint.h:: * stdio.h:: * stdlib.h:: +* stdnoreturn.h:: * string.h:: * strings.h:: * stropts.h:: @@ -1281,6 +1282,7 @@ which (known) portability problems are not worked around by Gnulib. @include posix-headers/stdint.texi @include posix-headers/stdio.texi @include posix-headers/stdlib.texi +@include posix-headers/stdnoreturn.texi @include posix-headers/string.texi @include posix-headers/strings.texi @include posix-headers/stropts.texi diff --git a/doc/posix-headers/stdnoreturn.texi b/doc/posix-headers/stdnoreturn.texi new file mode 100644 index 000000000..f49d66347 --- /dev/null +++ b/doc/posix-headers/stdnoreturn.texi @@ -0,0 +1,24 @@ +@node stdnoreturn.h +@section @file{stdnoreturn.h} + +POSIX specification:@* Not in POSIX yet, but we expect it will be. +ISO C11 (latest free draft +@url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf}) +sections 7.23. + +Gnulib module: stdnoreturn + +Portability problems fixed by Gnulib: +@itemize +@item +This header file is missing on most circa-2012 platforms. +@end itemize + +Portability problems not fixed by Gnulib: +@itemize +@item +@code{} should be #included before @samp{_Noreturn} is used. +@item +You cannot assume that @code{_Noreturn} is a reserved word; +it might be a macro. +@end itemize diff --git a/lib/stdnoreturn.in.h b/lib/stdnoreturn.in.h new file mode 100644 index 000000000..5ca30631f --- /dev/null +++ b/lib/stdnoreturn.in.h @@ -0,0 +1,38 @@ +/* A substitute for ISO C11 . + + Copyright 2012 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . */ + +/* Written by Paul Eggert. */ + +#ifndef noreturn + +/* ISO C11 for platforms that lack it. + + References: + ISO C11 (latest free draft + ) + section 7.23 */ + +/* The definition of _Noreturn is copied here. */ + +#define noreturn _Noreturn + +/* Did he ever return? + No he never returned + And his fate is still unlearn'd ... + -- Steiner J, Hawes BL. M.T.A. (1949) */ + +#endif /* noreturn */ diff --git a/m4/stdnoreturn.m4 b/m4/stdnoreturn.m4 new file mode 100644 index 000000000..6e10b120a --- /dev/null +++ b/m4/stdnoreturn.m4 @@ -0,0 +1,42 @@ +# Check for stdnoreturn.h that conforms to C11. + +dnl Copyright 2012 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +# Prepare for substituting if it is not supported. + +AC_DEFUN([gl_STDNORETURN_H], +[ + AC_CACHE_CHECK([for working stdnoreturn.h], + [gl_cv_header_working_stdnoreturn_h], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[#include + #include + void noreturn foo1 (void) { exit (0); } + void _Noreturn foo2 (void) { exit (0); } + noreturn void foo3 (void) { exit (0); } + _Noreturn void foo4 (void) { exit (0); } + int main (int argc, char **argv) { + if (argc & 1) + return 0; + ((argv[0][0] + ? (argv[0][1] ? foo1 : foo2) + : (argv[0][1] ? foo3 : foo4)) + ()); + } + ]])], + [gl_cv_header_working_stdnoreturn_h=yes], + [gl_cv_header_working_stdnoreturn_h=no])]) + + if test $gl_cv_header_working_stdnoreturn_h = yes; then + STDNORETURN_H='' + else + STDNORETURN_H='stdnoreturn.h' + fi + + AC_SUBST([STDNORETURN_H]) + AM_CONDITIONAL([GL_GENERATE_STDNORETURN_H], [test -n "$STDNORETURN_H"]) +]) diff --git a/modules/stdnoreturn b/modules/stdnoreturn new file mode 100644 index 000000000..acd661b28 --- /dev/null +++ b/modules/stdnoreturn @@ -0,0 +1,40 @@ +Description: +A that nearly conforms to ISO C11. + +Files: +lib/stdnoreturn.in.h +m4/stdnoreturn.m4 + +Depends-on: +snippet/_Noreturn + +configure.ac: +gl_STDNORETURN_H + +Makefile.am: +BUILT_SOURCES += $(STDNORETURN_H) + +# We need the following in order to create when the system +# doesn't have one that works. +if GL_GENERATE_STDNORETURN_H +stdnoreturn.h: stdnoreturn.in.h $(top_builddir)/config.status $(_NORETURN_H) + $(AM_V_GEN)rm -f $@-t $@ && \ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ + sed -e '/definition of _Noreturn/r $(_NORETURN_H)' \ + < $(srcdir)/stdnoreturn.in.h; \ + } > $@-t && \ + mv $@-t $@ +else +stdnoreturn.h: $(top_builddir)/config.status + rm -f $@ +endif +MOSTLYCLEANFILES += stdnoreturn.h stdnoreturn.h-t + +Include: + + +License: +LGPLv2+ + +Maintainer: +Paul Eggert diff --git a/modules/stdnoreturn-tests b/modules/stdnoreturn-tests new file mode 100644 index 000000000..1d1f82003 --- /dev/null +++ b/modules/stdnoreturn-tests @@ -0,0 +1,10 @@ +Files: +tests/test-stdnoreturn.c + +Depends-on: + +configure.ac: + +Makefile.am: +TESTS += test-stdnoreturn +check_PROGRAMS += test-stdnoreturn diff --git a/tests/test-stdnoreturn.c b/tests/test-stdnoreturn.c new file mode 100644 index 000000000..e8422ef16 --- /dev/null +++ b/tests/test-stdnoreturn.c @@ -0,0 +1,35 @@ +/* Test of . + Copyright 2012 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Written by Paul Eggert. */ + +#include + +#include + +#include + +noreturn void +does_not_return (void) +{ + exit (0); +} + +int +main (void) +{ + does_not_return (); +}