1 # wm_attributes.m4 - Macros to check compiler attributes and define macros
3 # Copyright (c) 2013 Christophe Curis
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 # Checks if the compiler supports ISO C11 noreturn attribute, if not
23 # try to define the keyword to a known syntax that does the job, or
24 # if nothing works sets it to empty to, at least, be able to
26 AC_DEFUN_ONCE([WM_C_NORETURN],
27 [AC_REQUIRE([_WM_SHELLFN_FUNCATTR])
28 AC_CACHE_CHECK([for noreturn], [wm_cv_c_noreturn],
33 #include <stdnoreturn.h>
35 /* Attribute in the prototype of the function */
36 noreturn int test_function(void);
38 /* Attribute on the function itself */
39 noreturn int test_function(void) {
42 ], [ test_function();])],
43 [wm_cv_c_noreturn=stdnoreturn],
45 "__attribute__((noreturn))" dnl for modern GCC-like compilers
46 "__attribute__((__noreturn__))" dnl for older GCC-like compilers
47 "__declspec(noreturn)" dnl for some other compilers
49 AS_IF([wm_fn_c_try_compile_funcattr "$wm_attr"],
50 [wm_cv_c_noreturn="$wm_attr" ; break])
53 AS_CASE([$wm_cv_c_noreturn],
55 [AC_DEFINE([HAVE_STDNORETURN], 1,
56 [Defined if header "stdnoreturn.h" exists, it defines ISO C11 attribute 'noreturn' and it works])],
58 [AC_DEFINE([noreturn], [],
59 [Defines the attribute to tell the compiler that a function never returns, if the ISO C11 attribute does not work])],
60 [AC_DEFINE_UNQUOTED([noreturn], [${wm_cv_c_noreturn}],
61 [Defines the attribute to tell the compiler that a function never returns, if the ISO C11 attribute does not work])])
64 # _WM_SHELLFN_FUNCATTRIBUTE
65 # ----------------------
66 # (internal shell function only!)
68 # Create a shell function to check if we can compile with special
70 AC_DEFUN([_WM_SHELLFN_FUNCATTR],
71 [@%:@ wm_fn_c_try_compile_funcattr ATTRIBUTE
72 @%:@ ---------------------------------------
73 @%:@ Try compiling a function with the attribute ATTRIBUTE
74 wm_fn_c_try_compile_funcattr ()
79 /* Attribute in the prototype of the function */
80 int test_function(int arg) $[]1;
82 /* Attribute on the function itself */
83 $[]1 int test_function(int arg) {
86 val = test_function(1);
90 AS_SET_STATUS([$wm_retval])