changeset 33161:e86c59dac135

Backed out changeset c23152b00d5f
author John W. Eaton <jwe@octave.org>
date Wed, 06 Mar 2024 22:54:49 -0500
parents 4584cb4207f1
children 5108f56fc8fc 4cbbc280c69d
files oct-conf-post-public.in.h
diffstat 1 files changed, 29 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
--- a/oct-conf-post-public.in.h	Sun Mar 03 11:16:26 2024 +0100
+++ b/oct-conf-post-public.in.h	Wed Mar 06 22:54:49 2024 -0500
@@ -32,54 +32,32 @@
 #define OCTAVE_BEGIN_NAMESPACE(name) namespace name {
 #define OCTAVE_END_NAMESPACE(name) }
 
-/* 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.  */
+/* 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.  */
 
 #if defined (__GNUC__)
-
-#  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
+   /* 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__))
 #  endif
 #  define HAVE_OCTAVE_DEPRECATED_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_NORETURN __attribute__ ((__noreturn__))
+#  define HAVE_OCTAVE_NORETURN_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
-
+#  define OCTAVE_UNUSED __attribute__ ((__unused__))
+#  define HAVE_OCTAVE_UNUSED_ATTR 1
 #else
 #  define OCTAVE_DEPRECATED(ver, msg)
-#  define OCTAVE_FALLTHROUGH ((void) 0)
 #  define OCTAVE_NORETURN
 #  define OCTAVE_UNUSED
 
@@ -89,10 +67,7 @@
 #endif
 
 /* Branch hint macros for use in if condititions.
-   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?  */
+   Returns logical value of x. */
 #if defined (__GNUC__)
 #  define OCTAVE_LIKELY(x) __builtin_expect (!!(x), 1)
 #  define OCTAVE_UNLIKELY(x) __builtin_expect (!!(x), 0)
@@ -129,6 +104,16 @@
 /* #  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