Re: git: c27a89971805 - main - stdlib.h: add __noexcept to prototypes

From: Konstantin Belousov <kostikbel_at_gmail.com>
Date: Fri, 02 Feb 2024 18:28:41 UTC
On Fri, Feb 02, 2024 at 06:16:59PM +0000, Warner Losh wrote:
> The branch main has been updated by imp:
> 
> URL: https://cgit.FreeBSD.org/src/commit/?id=c27a89971805b176dcfa5a234f2ea6f6109d0a70
> 
> commit c27a89971805b176dcfa5a234f2ea6f6109d0a70
> Author:     Lexi Winter <lexi@le-Fay.ORG>
> AuthorDate: 2024-02-02 16:41:40 +0000
> Commit:     Warner Losh <imp@FreeBSD.org>
> CommitDate: 2024-02-02 18:11:17 +0000
> 
>     stdlib.h: add __noexcept to prototypes
>     
>     The noexcept specifier is required on these functions in C++:
>     _Exit(), atexit(), quick_exit(), at_quick_exit(), abort().
>     
>     MFC after:      2 weeks
>     
>     Reviewed by: imp
>     Pull Request: https://github.com/freebsd/freebsd-src/pull/1085
> ---
>  include/stdlib.h | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/include/stdlib.h b/include/stdlib.h
> index ff8991d1fa94..f0687f01e6c7 100644
> --- a/include/stdlib.h
> +++ b/include/stdlib.h
> @@ -84,9 +84,9 @@ extern int __mb_cur_max;
>  extern int ___mb_cur_max(void);
>  #define	MB_CUR_MAX	((size_t)___mb_cur_max())
>  
> -_Noreturn void	 abort(void);
> +_Noreturn void	 abort(void) __noexcept;
>  int	 abs(int) __pure2;
> -int	 atexit(void (* _Nonnull)(void));
> +int	 atexit(void (* _Nonnull)(void)) __noexcept;
>  double	 atof(const char *);
>  int	 atoi(const char *);
>  long	 atol(const char *);
> @@ -154,7 +154,7 @@ unsigned long long
>  	 strtoull(const char * __restrict, char ** __restrict, int);
>  #endif /* __LONG_LONG_SUPPORTED */
>  
> -_Noreturn void	 _Exit(int);
> +_Noreturn void	 _Exit(int) __noexcept;
>  #endif /* __ISO_C_VISIBLE >= 1999 */
>  
>  /*
> @@ -163,9 +163,9 @@ _Noreturn void	 _Exit(int);
>  #if __ISO_C_VISIBLE >= 2011 || __cplusplus >= 201103L
>  void *	aligned_alloc(size_t, size_t) __malloc_like __alloc_align(1)
>  	    __alloc_size(2);
> -int	at_quick_exit(void (*)(void));
> +int	at_quick_exit(void (*)(void)) __noexcept;
>  _Noreturn void
> -	quick_exit(int);
> +	quick_exit(int) __noexcept;
This is wrong, libc quick_exit() does not provide such guarantees as
implemented. More, being part of libc it cannot ever guarantee that ever
(and call std::terminate if the requirement is violated).

Making it such would require bringing some C++ ABI into libc which I
object strongly.


>  #endif /* __ISO_C_VISIBLE >= 2011 */
>  /*
>   * Extensions made by POSIX relative to C.