changeset 33156:c23152b00d5f

update attribute macros now that we require C++17 * oct-conf-post-public.in.h (OCTAVE_DEPRECATED, OCTAVE_FALLTHROUGH, OCTAVE_NORETURN, OCTAVE_UNUSED): Assume C++ standard attributes are available to provide these macros.
author John W. Eaton <jwe@octave.org>
date Wed, 06 Mar 2024 12:39:58 -0500
parents f94a1dd11534
children 899647fde914 2ac3523783ee
files oct-conf-post-public.in.h
diffstat 1 files changed, 44 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/oct-conf-post-public.in.h	Wed Mar 06 12:37:47 2024 -0500
+++ b/oct-conf-post-public.in.h	Wed Mar 06 12:39:58 2024 -0500
@@ -32,32 +32,54 @@
 #define OCTAVE_BEGIN_NAMESPACE(name) namespace name {
 #define OCTAVE_END_NAMESPACE(name) }
 
-/* The C++ standard is evolving to allow attribute hints in a
-   compiler-independent manner.  In C++ 2011 support for noreturn was
-   added.  In C++ 2014 support for deprecated was added.  The Octave
-   code base has been future-proofed by using macros of the form
-   OCTAVE_ATTRIBUTE_NAME in place of vendor specific attribute
-   mechanisms.  As compilers evolve, the underlying implementation can
-   be changed with the macro definitions below.  FIXME: Update macros
-   to use C++ standard attribute syntax when Octave moves to C++ 2014
-   standard.  */
+/* We require C++17 now so it should be possible to use
+   [[deprecated(message)]], [[noreturn]], and [[unused]] unconditionally
+   but for now we'll keep the macros in case there is an issue.  Even if
+   we decide to use the C++ standard attributes directly in the Octave
+   sources without the macros, OCTAVE_DEPRECATED will still be useful to
+   provide consistent formatting of the version number.  */
 
 #if defined (__GNUC__)
-   /* The following attributes are used with gcc and clang compilers.  */
-#  if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
-#    define OCTAVE_DEPRECATED(ver, msg) __attribute__ ((__deprecated__ ("[" #ver "]: " msg)))
-#  else
-#    define OCTAVE_DEPRECATED(ver, msg) __attribute__ ((__deprecated__))
+
+#  if !defined (OCTAVE_DEPRECATED)
+#    if defined (__cplusplus)
+#      define OCTAVE_DEPRECATED(ver, msg) [[deprecated ("[" #ver "]: " msg)]]
+#    else
+#      define OCTAVE_DEPRECATED(ver, msg) __attribute__ ((__deprecated__ ("[" #ver "]: " msg)))
+#    endif
 #  endif
 #  define HAVE_OCTAVE_DEPRECATED_ATTR 1
 
-#  define OCTAVE_NORETURN __attribute__ ((__noreturn__))
-#  define HAVE_OCTAVE_NORETURN_ATTR 1
+#  if !defined (OCTAVE_FALLTHROUGH)
+#    if defined (__cplusplus)
+#      define OCTAVE_FALLTHROUGH [[fallthrough]]
+#    else
+#      define OCTAVE_FALLTHROUGH __attribute__ ((__fallthrough__))
+#    endif
+#    define HAVE_OCTAVE_FALLTHROUGH_ATTR 1
+#  endif
 
-#  define OCTAVE_UNUSED __attribute__ ((__unused__))
-#  define HAVE_OCTAVE_UNUSED_ATTR 1
+#  if !defined (OCTAVE_NORETURN)
+#    if defined (__cplusplus)
+#      define OCTAVE_NORETURN [[noreturn]]
+#    else
+#      define OCTAVE_NORETURN __attribute__ ((__noreturn__))
+#    endif
+#    define HAVE_OCTAVE_NORETURN_ATTR 1
+#  endif
+
+#  if !defined (OCTAVE_UNUSED)
+#    if defined (__cplusplus)
+#      define OCTAVE_UNUSED [[maybe_unused]]
+#    else
+#      define OCTAVE_UNUSED __attribute__ ((__unused__))
+#    endif
+#    define HAVE_OCTAVE_UNUSED_ATTR 1
+#  endif
+
 #else
 #  define OCTAVE_DEPRECATED(ver, msg)
+#  define OCTAVE_FALLTHROUGH ((void) 0)
 #  define OCTAVE_NORETURN
 #  define OCTAVE_UNUSED
 
@@ -67,7 +89,10 @@
 #endif
 
 /* Branch hint macros for use in if condititions.
-   Returns logical value of x. */
+   Returns logical value of x.
+
+   FIXME: With C++20, can we use [[likely]] and [[unlikely]]?  If so,
+   what is the purpose of the argument X in the macros below?  */
 #if defined (__GNUC__)
 #  define OCTAVE_LIKELY(x) __builtin_expect (!!(x), 1)
 #  define OCTAVE_UNLIKELY(x) __builtin_expect (!!(x), 0)
@@ -104,16 +129,6 @@
 /* #  undef HAVE_OCTAVE_FORMAT_PRINTF_ATTR */
 #endif
 
-#if ! defined (OCTAVE_FALLTHROUGH)
-#  if defined (__cplusplus) && __cplusplus > 201402L
-#    define OCTAVE_FALLTHROUGH [[fallthrough]]
-#  elif defined (__GNUC__) && __GNUC__ < 7
-#    define OCTAVE_FALLTHROUGH ((void) 0)
-#  else
-#    define OCTAVE_FALLTHROUGH __attribute__ ((__fallthrough__))
-#  endif
-#endif
-
 #if defined (__cplusplus)
 template <typename T>
 static inline void