| 1 |
# |
| 2 |
# SYNOPSIS |
| 3 |
# |
| 4 |
# DLP_FALLTHROUGH |
| 5 |
# |
| 6 |
# DESCRIPTION |
| 7 |
# |
| 8 |
# This macro checks if the compiler supports a fallthrough warning |
| 9 |
# suppression attribute in GCC or CLANG style. |
| 10 |
# |
| 11 |
# If a fallthrough warning suppression attribute is supported define |
| 12 |
# HAVE_<STYLE>_ATTRIBUTE_FALLTHROUGH. |
| 13 |
# |
| 14 |
# The macro caches its result in ax_cv_have_<style>_attribute_fallthrough |
| 15 |
# variables. |
| 16 |
# |
| 17 |
# LICENSE |
| 18 |
# |
| 19 |
# Copyright (c) 2017 David Tardon <[email protected]> |
| 20 |
# |
| 21 |
# Copying and distribution of this file, with or without modification, are |
| 22 |
# permitted in any medium without royalty provided the copyright notice |
| 23 |
# and this notice are preserved. This file is offered as-is, without any |
| 24 |
# warranty. |
| 25 |
|
| 26 |
#serial 1 |
| 27 |
|
| 28 |
m4_defun([_DLP_FALLTHROUGH], [ |
| 29 |
AS_VAR_PUSHDEF([ac_var], [ax_cv_have_$2_attribute_falltrough]) |
| 30 |
|
| 31 |
AC_CACHE_CHECK([for $1], [ac_var], [ |
| 32 |
AC_LINK_IFELSE([AC_LANG_PROGRAM([ |
| 33 |
void foo(int &i) |
| 34 |
{ |
| 35 |
switch (i) |
| 36 |
{ |
| 37 |
case 0: |
| 38 |
i += 1; |
| 39 |
$1; |
| 40 |
default: |
| 41 |
i += 1; |
| 42 |
} |
| 43 |
} |
| 44 |
], []) |
| 45 |
], |
| 46 |
dnl GCC doesn't exit with an error if an unknown attribute is |
| 47 |
dnl provided but only outputs a warning, so accept the attribute |
| 48 |
dnl only if no warning were issued. |
| 49 |
[AS_IF([test -s conftest.err], |
| 50 |
[AS_VAR_SET([ac_var], [no])], |
| 51 |
[AS_VAR_SET([ac_var], [yes])])], |
| 52 |
[AS_VAR_SET([ac_var], [no])]) |
| 53 |
]) |
| 54 |
|
| 55 |
AS_IF([test yes = AS_VAR_GET([ac_var])], |
| 56 |
[AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_$3_ATTRIBUTE_FALLTHROUGH), 1, |
| 57 |
[Define to 1 if the system has the $4-style `fallthrough' attribute])], []) |
| 58 |
|
| 59 |
AS_VAR_POPDEF([ac_var]) |
| 60 |
]) |
| 61 |
|
| 62 |
AC_DEFUN([DLP_FALLTHROUGH], [ |
| 63 |
_DLP_FALLTHROUGH([[__attribute__((fallthrough))]], [gcc], [GCC], [GNU]) |
| 64 |
_DLP_FALLTHROUGH([[[[clang:fallthrough]]]], [clang], [CLANG], [clang]) |
| 65 |
]) |