File: dlp_fallthrough.m4

package info (click to toggle)
libwps 0.4.14-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,700 kB
  • sloc: cpp: 77,505; sh: 4,699; makefile: 424; ansic: 4
file content (65 lines) | stat: -rw-r--r-- 2,043 bytes parent folder | download | duplicates (15)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#
# SYNOPSIS
#
#   DLP_FALLTHROUGH
#
# DESCRIPTION
#
#   This macro checks if the compiler supports a fallthrough warning
#   suppression attribute in GCC or CLANG style.
#
#   If a fallthrough warning suppression attribute is supported define
#   HAVE_<STYLE>_ATTRIBUTE_FALLTHROUGH.
#
#   The macro caches its result in ax_cv_have_<style>_attribute_fallthrough
#   variables.
#
# LICENSE
#
#   Copyright (c) 2017 David Tardon <dtardon@redhat.com>
#
#   Copying and distribution of this file, with or without modification, are
#   permitted in any medium without royalty provided the copyright notice
#   and this notice are preserved.  This file is offered as-is, without any
#   warranty.

#serial 1

m4_defun([_DLP_FALLTHROUGH], [
    AS_VAR_PUSHDEF([ac_var], [ax_cv_have_$2_attribute_falltrough])

    AC_CACHE_CHECK([for $1], [ac_var], [
        AC_LINK_IFELSE([AC_LANG_PROGRAM([
                void foo(int &i)
                {
                    switch (i)
                    {
                        case 0:
                            i += 1;
                            $1;
                        default:
                            i += 1;
                    }
                }
            ], [])
            ],
            dnl GCC doesn't exit with an error if an unknown attribute is
            dnl provided but only outputs a warning, so accept the attribute
            dnl only if no warning were issued.
            [AS_IF([test -s conftest.err],
                [AS_VAR_SET([ac_var], [no])],
                [AS_VAR_SET([ac_var], [yes])])],
            [AS_VAR_SET([ac_var], [no])])
    ])

    AS_IF([test yes = AS_VAR_GET([ac_var])],
        [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_$3_ATTRIBUTE_FALLTHROUGH), 1,
            [Define to 1 if the system has the $4-style `fallthrough' attribute])], [])

    AS_VAR_POPDEF([ac_var])
])

AC_DEFUN([DLP_FALLTHROUGH], [
    _DLP_FALLTHROUGH([[__attribute__((fallthrough))]], [gcc], [GCC], [GNU])
    _DLP_FALLTHROUGH([[[[clang::fallthrough]]]], [clang], [CLANG], [clang])
])