Mercurial > hg > octave-lojdl > gnulib-hg
changeset 16388:d0e332889b10
stdnoreturn: new module
This implements a replacement for C11's <stdnoreturn.h>.
* 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.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Fri, 24 Feb 2012 13:52:45 -0800 |
parents | 53295e65981f |
children | a9eaa22dc3f6 |
files | ChangeLog doc/gnulib.texi doc/posix-headers/stdnoreturn.texi lib/stdnoreturn.in.h m4/stdnoreturn.m4 modules/stdnoreturn modules/stdnoreturn-tests tests/test-stdnoreturn.c |
diffstat | 8 files changed, 200 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2012-02-24 Paul Eggert <eggert@cs.ucla.edu> + + stdnoreturn: new module + This implements a replacement for C11's <stdnoreturn.h>. + * 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 <sbrabec@suse.cz> (tiny change) regex: fix false multibyte matches in some regular expressions
--- a/doc/gnulib.texi +++ b/doc/gnulib.texi @@ -1194,6 +1194,7 @@ * stdint.h:: * stdio.h:: * stdlib.h:: +* stdnoreturn.h:: * string.h:: * strings.h:: * stropts.h:: @@ -1281,6 +1282,7 @@ @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
new file mode 100644 --- /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{<stdnoreturn.h>} 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
new file mode 100644 --- /dev/null +++ b/lib/stdnoreturn.in.h @@ -0,0 +1,38 @@ +/* A substitute for ISO C11 <stdnoreturn.h>. + + 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 <http://www.gnu.org/licenses/>. */ + +/* Written by Paul Eggert. */ + +#ifndef noreturn + +/* ISO C11 <stdnoreturn.h> for platforms that lack it. + + References: + ISO C11 (latest free draft + <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf>) + 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 */
new file mode 100644 --- /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 <stdnoreturn.h> 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 <stdlib.h> + #include <stdnoreturn.h> + 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"]) +])
new file mode 100644 --- /dev/null +++ b/modules/stdnoreturn @@ -0,0 +1,40 @@ +Description: +A <stdnoreturn.h> 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 <stdnoreturn.h> 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: +<stdnoreturn.h> + +License: +LGPLv2+ + +Maintainer: +Paul Eggert
new file mode 100644 --- /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
new file mode 100644 --- /dev/null +++ b/tests/test-stdnoreturn.c @@ -0,0 +1,35 @@ +/* Test of <stdnoreturn.h>. + 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 <http://www.gnu.org/licenses/>. */ + +/* Written by Paul Eggert. */ + +#include <config.h> + +#include <stdnoreturn.h> + +#include <stdlib.h> + +noreturn void +does_not_return (void) +{ + exit (0); +} + +int +main (void) +{ + does_not_return (); +}