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.
23 # Checks if the compiler supports ISO C11 noreturn attribute, if not
24 # try to define the keyword to a known syntax that does the job, or
25 # if nothing works sets it to empty to, at least, be able to
27 AC_DEFUN_ONCE([WM_C_NORETURN],
28 [AC_REQUIRE([_WM_SHELLFN_FUNCATTR])
29 AC_CACHE_CHECK([for noreturn], [wm_cv_c_noreturn],
34 #include <stdnoreturn.h>
36 /* Attribute in the prototype of the function */
37 noreturn int test_function(void);
39 /* Attribute on the function itself */
40 noreturn int test_function(void) {
43 ], [ test_function();])],
44 [wm_cv_c_noreturn=stdnoreturn],
46 "__attribute__((noreturn))" dnl for modern GCC-like compilers
47 "__attribute__((__noreturn__))" dnl for older GCC-like compilers
48 "__declspec(noreturn)" dnl for some other compilers
50 AS_IF([wm_fn_c_try_compile_funcattr "$wm_attr"],
51 [wm_cv_c_noreturn="$wm_attr" ; break])
54 AS_CASE([$wm_cv_c_noreturn],
56 [AC_DEFINE([HAVE_STDNORETURN], 1,
57 [Defined if header "stdnoreturn.h" exists, it defines ISO C11 attribute 'noreturn' and it works])],
59 [AC_DEFINE([noreturn], [],
60 [Defines the attribute to tell the compiler that a function never returns, if the ISO C11 attribute does not work])],
61 [AC_DEFINE_UNQUOTED([noreturn], [${wm_cv_c_noreturn}],
62 [Defines the attribute to tell the compiler that a function never returns, if the ISO C11 attribute does not work])])
66 # _WM_SHELLFN_FUNCATTRIBUTE
67 # -------------------------
68 # (internal shell function only!)
70 # Create a shell function to check if we can compile with special
72 AC_DEFUN([_WM_SHELLFN_FUNCATTR],
73 [@%:@ wm_fn_c_try_compile_funcattr ATTRIBUTE
74 @%:@ ---------------------------------------
75 @%:@ Try compiling a function with the attribute ATTRIBUTE
76 wm_fn_c_try_compile_funcattr ()
81 /* Attribute in the prototype of the function */
82 int test_function(int arg) $[]1;
84 /* Attribute on the function itself */
85 $[]1 int test_function(int arg) {
88 val = test_function(1);
92 AS_SET_STATUS([$wm_retval])