diff --git a/config.h.in b/config.h.in index 92216df4d..8c617c3fd 100644 --- a/config.h.in +++ b/config.h.in @@ -1476,10 +1476,17 @@ #endif /* For functions that call exit() directly. */ -#if __GNUC_PREREQ__(2, 5) -# define sudo_noreturn __attribute__((__noreturn__)) -#else -# define sudo_noreturn +#ifdef __has_c_attribute +# if __has_c_attribute(__noreturn__) +# define sudo_noreturn [[__noreturn__]] +# endif +#endif +#ifndef sudo_noreturn +# if __GNUC_PREREQ__(2, 5) +# define sudo_noreturn __attribute__((__noreturn__)) +# else +# define sudo_noreturn +# endif #endif /* For malloc-like functions that return uninitialized or zeroed memory. */ @@ -1507,6 +1514,20 @@ # define sudo_attr_fmt_arg(_f) #endif +/* C23 defines a fallthrough attribute, gcc 7.0 and clang 10 have their own. */ +#ifdef __has_c_attribute +# if __has_c_attribute(__fallthrough__) +# define FALLTHROUGH [[__fallthrough__]] +# endif +#endif +#ifndef FALLTHROUGH +# if defined(HAVE_FALLTHROUGH_ATTRIBUTE) +# define FALLTHROUGH __attribute__((__fallthrough__)) +# else +# define FALLTHROUGH do { } while (0) +# endif +#endif + /* Symbol visibility controls. */ #ifdef HAVE_DSO_VISIBILITY # if defined(__GNUC__) diff --git a/configure.ac b/configure.ac index 261579bfc..e37fe6027 100644 --- a/configure.ac +++ b/configure.ac @@ -5571,10 +5571,17 @@ AH_BOTTOM([#ifndef __GNUC_PREREQ__ #endif /* For functions that call exit() directly. */ -#if __GNUC_PREREQ__(2, 5) -# define sudo_noreturn __attribute__((__noreturn__)) -#else -# define sudo_noreturn +#ifdef __has_c_attribute +# if __has_c_attribute(__noreturn__) +# define sudo_noreturn [[__noreturn__]] +# endif +#endif +#ifndef sudo_noreturn +# if __GNUC_PREREQ__(2, 5) +# define sudo_noreturn __attribute__((__noreturn__)) +# else +# define sudo_noreturn +# endif #endif /* For malloc-like functions that return uninitialized or zeroed memory. */ @@ -5602,6 +5609,20 @@ AH_BOTTOM([#ifndef __GNUC_PREREQ__ # define sudo_attr_fmt_arg(_f) #endif +/* C23 defines a fallthrough attribute, gcc 7.0 and clang 10 have their own. */ +#ifdef __has_c_attribute +# if __has_c_attribute(__fallthrough__) +# define FALLTHROUGH [[__fallthrough__]] +# endif +#endif +#ifndef FALLTHROUGH +# if defined(HAVE_FALLTHROUGH_ATTRIBUTE) +# define FALLTHROUGH __attribute__((__fallthrough__)) +# else +# define FALLTHROUGH do { } while (0) +# endif +#endif + /* Symbol visibility controls. */ #ifdef HAVE_DSO_VISIBILITY # if defined(__GNUC__) diff --git a/include/sudo_compat.h b/include/sudo_compat.h index 4437a1c3b..edf609ea8 100644 --- a/include/sudo_compat.h +++ b/include/sudo_compat.h @@ -37,12 +37,6 @@ * Macros and functions that may be missing on some operating systems. */ -#ifdef HAVE_FALLTHROUGH_ATTRIBUTE -# define FALLTHROUGH __attribute__((__fallthrough__)) -#else -# define FALLTHROUGH do { } while (0) -#endif - /* * Given the pointer x to the member m of the struct s, return * a pointer to the containing structure.