diff mbox series

[1/8] Move FINAL and OVERRIDE from ansidecl.h to gcc-plugin.h

Message ID 20220519123208.3388554-1-dmalcolm@redhat.com
State New
Headers show
Series [1/8] Move FINAL and OVERRIDE from ansidecl.h to gcc-plugin.h | expand

Commit Message

David Malcolm May 19, 2022, 12:32 p.m. UTC
As of GCC 11 onwards we have required a C++11 compiler, such as GCC 4.8
or later.  On the assumption that any such compiler correctly implements
"final" and "override", this patch removes the FINAL and OVERRIDE macros
from ansidecl.h.  It adds them back to gcc-plugins.h in case any plugins
make use of them.

Followup patches within this kit replace all uses of the macros in the
tree with the lower-case versions; I've split them up for ease of
review, but would apply them as one combined commit if approved.

gcc/ChangeLog:
	* gcc-plugin.h: Add macros OVERRIDE and FINAL.

include/ChangeLog:
	* ansidecl.h: Drop macros OVERRIDE and FINAL.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
---
 gcc/gcc-plugin.h   |  7 +++++++
 include/ansidecl.h | 41 -----------------------------------------
 2 files changed, 7 insertions(+), 41 deletions(-)

Comments

David Malcolm May 19, 2022, 12:35 p.m. UTC | #1
On Thu, 2022-05-19 at 08:32 -0400, David Malcolm wrote:
> As of GCC 11 onwards we have required a C++11 compiler, such as GCC
> 4.8
> or later.  On the assumption that any such compiler correctly
> implements
> "final" and "override", this patch removes the FINAL and OVERRIDE
> macros
> from ansidecl.h.  It adds them back to gcc-plugins.h in case any
> plugins
> make use of them.
> 
> Followup patches within this kit replace all uses of the macros in
> the
> tree with the lower-case versions; I've split them up for ease of
> review, but would apply them as one combined commit if approved.

I forgot to say:
I've successfully bootstrapped & regrtested the combined patches on
x86_64-pc-linux-gnu, and (very) lightly tested them on aarch64-linux-
gnu.

Dave

> 
> gcc/ChangeLog:
>         * gcc-plugin.h: Add macros OVERRIDE and FINAL.
> 
> include/ChangeLog:
>         * ansidecl.h: Drop macros OVERRIDE and FINAL.
> 
> Signed-off-by: David Malcolm <dmalcolm@redhat.com>
> ---
>  gcc/gcc-plugin.h   |  7 +++++++
>  include/ansidecl.h | 41 -----------------------------------------
>  2 files changed, 7 insertions(+), 41 deletions(-)
> 
> diff --git a/gcc/gcc-plugin.h b/gcc/gcc-plugin.h
> index ee9aa865114..f0f3049d0ce 100644
> --- a/gcc/gcc-plugin.h
> +++ b/gcc/gcc-plugin.h
> @@ -44,4 +44,11 @@ along with GCC; see the file COPYING3.  If not see
>  #include "tree-check.h"
>  #include "plugin.h"
>  
> +/* Versions of GCC prior to GCC 13 defined these macros in
> ansidecl.h
> +   for C++98 compatibility.  Given that we require C++11 from GCC 11
> onwards,
> +   keep definitions here in case plugins made use of them.  */
> +
> +#define OVERRIDE override
> +#define FINAL    final
> +
>  #endif /* GCC_PLUGIN_H */
> diff --git a/include/ansidecl.h b/include/ansidecl.h
> index efee5b6904b..119748deb68 100644
> --- a/include/ansidecl.h
> +++ b/include/ansidecl.h
> @@ -345,47 +345,6 @@ So instead we use the macro below and test it
> against specific values.  */
>  #define CONSTEXPR
>  #endif
>  
> -/* C++11 adds the ability to add "override" after an implementation
> of a
> -   virtual function in a subclass, to:
> -     (A) document that this is an override of a virtual function
> -     (B) allow the compiler to issue a warning if it isn't (e.g. a
> mismatch
> -         of the type signature).
> -
> -   Similarly, it allows us to add a "final" to indicate that no
> subclass
> -   may subsequently override the vfunc.
> -
> -   Provide OVERRIDE and FINAL as macros, allowing us to get these
> benefits
> -   when compiling with C++11 support, but without requiring C++11.
> -
> -   For gcc, use "-std=c++11" to enable C++11 support; gcc 6 onwards
> enables
> -   this by default (actually GNU++14).  */
> -
> -#if defined __cplusplus
> -# if __cplusplus >= 201103
> -   /* C++11 claims to be available: use it.  Final/override were
> only
> -      implemented in 4.7, though.  */
> -#  if GCC_VERSION < 4007
> -#   define OVERRIDE
> -#   define FINAL
> -#  else
> -#   define OVERRIDE override
> -#   define FINAL final
> -#  endif
> -# elif GCC_VERSION >= 4007
> -   /* G++ 4.7 supports __final in C++98.  */
> -#  define OVERRIDE
> -#  define FINAL __final
> -# else
> -   /* No C++11 support; leave the macros empty.  */
> -#  define OVERRIDE
> -#  define FINAL
> -# endif
> -#else
> -  /* No C++11 support; leave the macros empty.  */
> -# define OVERRIDE
> -# define FINAL
> -#endif
> -
>  /* A macro to disable the copy constructor and assignment operator.
>     When building with C++11 and above, the methods are explicitly
>     deleted, causing a compile-time error if something tries to copy.
Richard Biener May 19, 2022, 12:37 p.m. UTC | #2
On Thu, May 19, 2022 at 2:33 PM David Malcolm via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> As of GCC 11 onwards we have required a C++11 compiler, such as GCC 4.8
> or later.  On the assumption that any such compiler correctly implements
> "final" and "override", this patch removes the FINAL and OVERRIDE macros
> from ansidecl.h.  It adds them back to gcc-plugins.h in case any plugins
> make use of them.

I don't think we need to care for that case so please do not add them to
gcc-plugins.h.

But ansidecl.h is shared between gcc and binutils/gdb (and libiberty
in general),
can you get an ack from their side as well please?

Thanks,
Richard.

> Followup patches within this kit replace all uses of the macros in the
> tree with the lower-case versions; I've split them up for ease of
> review, but would apply them as one combined commit if approved.
>
> gcc/ChangeLog:
>         * gcc-plugin.h: Add macros OVERRIDE and FINAL.
>
> include/ChangeLog:
>         * ansidecl.h: Drop macros OVERRIDE and FINAL.
>
> Signed-off-by: David Malcolm <dmalcolm@redhat.com>
> ---
>  gcc/gcc-plugin.h   |  7 +++++++
>  include/ansidecl.h | 41 -----------------------------------------
>  2 files changed, 7 insertions(+), 41 deletions(-)
>
> diff --git a/gcc/gcc-plugin.h b/gcc/gcc-plugin.h
> index ee9aa865114..f0f3049d0ce 100644
> --- a/gcc/gcc-plugin.h
> +++ b/gcc/gcc-plugin.h
> @@ -44,4 +44,11 @@ along with GCC; see the file COPYING3.  If not see
>  #include "tree-check.h"
>  #include "plugin.h"
>
> +/* Versions of GCC prior to GCC 13 defined these macros in ansidecl.h
> +   for C++98 compatibility.  Given that we require C++11 from GCC 11 onwards,
> +   keep definitions here in case plugins made use of them.  */
> +
> +#define OVERRIDE override
> +#define FINAL    final
> +
>  #endif /* GCC_PLUGIN_H */
> diff --git a/include/ansidecl.h b/include/ansidecl.h
> index efee5b6904b..119748deb68 100644
> --- a/include/ansidecl.h
> +++ b/include/ansidecl.h
> @@ -345,47 +345,6 @@ So instead we use the macro below and test it against specific values.  */
>  #define CONSTEXPR
>  #endif
>
> -/* C++11 adds the ability to add "override" after an implementation of a
> -   virtual function in a subclass, to:
> -     (A) document that this is an override of a virtual function
> -     (B) allow the compiler to issue a warning if it isn't (e.g. a mismatch
> -         of the type signature).
> -
> -   Similarly, it allows us to add a "final" to indicate that no subclass
> -   may subsequently override the vfunc.
> -
> -   Provide OVERRIDE and FINAL as macros, allowing us to get these benefits
> -   when compiling with C++11 support, but without requiring C++11.
> -
> -   For gcc, use "-std=c++11" to enable C++11 support; gcc 6 onwards enables
> -   this by default (actually GNU++14).  */
> -
> -#if defined __cplusplus
> -# if __cplusplus >= 201103
> -   /* C++11 claims to be available: use it.  Final/override were only
> -      implemented in 4.7, though.  */
> -#  if GCC_VERSION < 4007
> -#   define OVERRIDE
> -#   define FINAL
> -#  else
> -#   define OVERRIDE override
> -#   define FINAL final
> -#  endif
> -# elif GCC_VERSION >= 4007
> -   /* G++ 4.7 supports __final in C++98.  */
> -#  define OVERRIDE
> -#  define FINAL __final
> -# else
> -   /* No C++11 support; leave the macros empty.  */
> -#  define OVERRIDE
> -#  define FINAL
> -# endif
> -#else
> -  /* No C++11 support; leave the macros empty.  */
> -# define OVERRIDE
> -# define FINAL
> -#endif
> -
>  /* A macro to disable the copy constructor and assignment operator.
>     When building with C++11 and above, the methods are explicitly
>     deleted, causing a compile-time error if something tries to copy.
> --
> 2.26.3
>
Richard Biener May 19, 2022, 12:45 p.m. UTC | #3
On Thu, May 19, 2022 at 2:43 PM David Malcolm via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> On Thu, 2022-05-19 at 08:32 -0400, David Malcolm wrote:
> > As of GCC 11 onwards we have required a C++11 compiler, such as GCC
> > 4.8
> > or later.  On the assumption that any such compiler correctly
> > implements
> > "final" and "override", this patch removes the FINAL and OVERRIDE
> > macros
> > from ansidecl.h.  It adds them back to gcc-plugins.h in case any
> > plugins
> > make use of them.
> >
> > Followup patches within this kit replace all uses of the macros in
> > the
> > tree with the lower-case versions; I've split them up for ease of
> > review, but would apply them as one combined commit if approved.
>
> I forgot to say:
> I've successfully bootstrapped & regrtested the combined patches on
> x86_64-pc-linux-gnu, and (very) lightly tested them on aarch64-linux-
> gnu.

And I forgot to say - the patches doing the replacement are fine en-bloc

Thanks,
Richard.

> Dave
>
> >
> > gcc/ChangeLog:
> >         * gcc-plugin.h: Add macros OVERRIDE and FINAL.
> >
> > include/ChangeLog:
> >         * ansidecl.h: Drop macros OVERRIDE and FINAL.
> >
> > Signed-off-by: David Malcolm <dmalcolm@redhat.com>
> > ---
> >  gcc/gcc-plugin.h   |  7 +++++++
> >  include/ansidecl.h | 41 -----------------------------------------
> >  2 files changed, 7 insertions(+), 41 deletions(-)
> >
> > diff --git a/gcc/gcc-plugin.h b/gcc/gcc-plugin.h
> > index ee9aa865114..f0f3049d0ce 100644
> > --- a/gcc/gcc-plugin.h
> > +++ b/gcc/gcc-plugin.h
> > @@ -44,4 +44,11 @@ along with GCC; see the file COPYING3.  If not see
> >  #include "tree-check.h"
> >  #include "plugin.h"
> >
> > +/* Versions of GCC prior to GCC 13 defined these macros in
> > ansidecl.h
> > +   for C++98 compatibility.  Given that we require C++11 from GCC 11
> > onwards,
> > +   keep definitions here in case plugins made use of them.  */
> > +
> > +#define OVERRIDE override
> > +#define FINAL    final
> > +
> >  #endif /* GCC_PLUGIN_H */
> > diff --git a/include/ansidecl.h b/include/ansidecl.h
> > index efee5b6904b..119748deb68 100644
> > --- a/include/ansidecl.h
> > +++ b/include/ansidecl.h
> > @@ -345,47 +345,6 @@ So instead we use the macro below and test it
> > against specific values.  */
> >  #define CONSTEXPR
> >  #endif
> >
> > -/* C++11 adds the ability to add "override" after an implementation
> > of a
> > -   virtual function in a subclass, to:
> > -     (A) document that this is an override of a virtual function
> > -     (B) allow the compiler to issue a warning if it isn't (e.g. a
> > mismatch
> > -         of the type signature).
> > -
> > -   Similarly, it allows us to add a "final" to indicate that no
> > subclass
> > -   may subsequently override the vfunc.
> > -
> > -   Provide OVERRIDE and FINAL as macros, allowing us to get these
> > benefits
> > -   when compiling with C++11 support, but without requiring C++11.
> > -
> > -   For gcc, use "-std=c++11" to enable C++11 support; gcc 6 onwards
> > enables
> > -   this by default (actually GNU++14).  */
> > -
> > -#if defined __cplusplus
> > -# if __cplusplus >= 201103
> > -   /* C++11 claims to be available: use it.  Final/override were
> > only
> > -      implemented in 4.7, though.  */
> > -#  if GCC_VERSION < 4007
> > -#   define OVERRIDE
> > -#   define FINAL
> > -#  else
> > -#   define OVERRIDE override
> > -#   define FINAL final
> > -#  endif
> > -# elif GCC_VERSION >= 4007
> > -   /* G++ 4.7 supports __final in C++98.  */
> > -#  define OVERRIDE
> > -#  define FINAL __final
> > -# else
> > -   /* No C++11 support; leave the macros empty.  */
> > -#  define OVERRIDE
> > -#  define FINAL
> > -# endif
> > -#else
> > -  /* No C++11 support; leave the macros empty.  */
> > -# define OVERRIDE
> > -# define FINAL
> > -#endif
> > -
> >  /* A macro to disable the copy constructor and assignment operator.
> >     When building with C++11 and above, the methods are explicitly
> >     deleted, causing a compile-time error if something tries to copy.
>
>
David Malcolm May 20, 2022, 2:20 p.m. UTC | #4
On Thu, 2022-05-19 at 14:45 +0200, Richard Biener wrote:
> On Thu, May 19, 2022 at 2:43 PM David Malcolm via Gcc-patches
> <gcc-patches@gcc.gnu.org> wrote:
> > 
> > On Thu, 2022-05-19 at 08:32 -0400, David Malcolm wrote:
> > > As of GCC 11 onwards we have required a C++11 compiler, such as
> > > GCC
> > > 4.8
> > > or later.  On the assumption that any such compiler correctly
> > > implements
> > > "final" and "override", this patch removes the FINAL and OVERRIDE
> > > macros
> > > from ansidecl.h.  It adds them back to gcc-plugins.h in case any
> > > plugins
> > > make use of them.
> > > 
> > > Followup patches within this kit replace all uses of the macros
> > > in
> > > the
> > > tree with the lower-case versions; I've split them up for ease of
> > > review, but would apply them as one combined commit if approved.
> > 
> > I forgot to say:
> > I've successfully bootstrapped & regrtested the combined patches on
> > x86_64-pc-linux-gnu, and (very) lightly tested them on aarch64-
> > linux-
> > gnu.
> 
> And I forgot to say - the patches doing the replacement are fine en-
> bloc

Thanks.  I merged those parts of the kit (patches 2-8, replacing the
macros uses with the lower-case specifiers directly) into one patch,
retested with just that, and have pushed it to trunk as r13-690-
gff171cb13df671.  I plan to look at the libiberty discussion early next
week.

Dave

> 
> Thanks,
> Richard.
> 
> > Dave
> > 
> > > 
> > > gcc/ChangeLog:
> > >         * gcc-plugin.h: Add macros OVERRIDE and FINAL.
> > > 
> > > include/ChangeLog:
> > >         * ansidecl.h: Drop macros OVERRIDE and FINAL.
> > > 
> > > Signed-off-by: David Malcolm <dmalcolm@redhat.com>
> > > ---
> > >  gcc/gcc-plugin.h   |  7 +++++++
> > >  include/ansidecl.h | 41 ----------------------------------------
> > > -
> > >  2 files changed, 7 insertions(+), 41 deletions(-)
> > > 
> > > diff --git a/gcc/gcc-plugin.h b/gcc/gcc-plugin.h
> > > index ee9aa865114..f0f3049d0ce 100644
> > > --- a/gcc/gcc-plugin.h
> > > +++ b/gcc/gcc-plugin.h
> > > @@ -44,4 +44,11 @@ along with GCC; see the file COPYING3.  If not
> > > see
> > >  #include "tree-check.h"
> > >  #include "plugin.h"
> > > 
> > > +/* Versions of GCC prior to GCC 13 defined these macros in
> > > ansidecl.h
> > > +   for C++98 compatibility.  Given that we require C++11 from
> > > GCC 11
> > > onwards,
> > > +   keep definitions here in case plugins made use of them.  */
> > > +
> > > +#define OVERRIDE override
> > > +#define FINAL    final
> > > +
> > >  #endif /* GCC_PLUGIN_H */
> > > diff --git a/include/ansidecl.h b/include/ansidecl.h
> > > index efee5b6904b..119748deb68 100644
> > > --- a/include/ansidecl.h
> > > +++ b/include/ansidecl.h
> > > @@ -345,47 +345,6 @@ So instead we use the macro below and test
> > > it
> > > against specific values.  */
> > >  #define CONSTEXPR
> > >  #endif
> > > 
> > > -/* C++11 adds the ability to add "override" after an
> > > implementation
> > > of a
> > > -   virtual function in a subclass, to:
> > > -     (A) document that this is an override of a virtual function
> > > -     (B) allow the compiler to issue a warning if it isn't (e.g.
> > > a
> > > mismatch
> > > -         of the type signature).
> > > -
> > > -   Similarly, it allows us to add a "final" to indicate that no
> > > subclass
> > > -   may subsequently override the vfunc.
> > > -
> > > -   Provide OVERRIDE and FINAL as macros, allowing us to get
> > > these
> > > benefits
> > > -   when compiling with C++11 support, but without requiring
> > > C++11.
> > > -
> > > -   For gcc, use "-std=c++11" to enable C++11 support; gcc 6
> > > onwards
> > > enables
> > > -   this by default (actually GNU++14).  */
> > > -
> > > -#if defined __cplusplus
> > > -# if __cplusplus >= 201103
> > > -   /* C++11 claims to be available: use it.  Final/override were
> > > only
> > > -      implemented in 4.7, though.  */
> > > -#  if GCC_VERSION < 4007
> > > -#   define OVERRIDE
> > > -#   define FINAL
> > > -#  else
> > > -#   define OVERRIDE override
> > > -#   define FINAL final
> > > -#  endif
> > > -# elif GCC_VERSION >= 4007
> > > -   /* G++ 4.7 supports __final in C++98.  */
> > > -#  define OVERRIDE
> > > -#  define FINAL __final
> > > -# else
> > > -   /* No C++11 support; leave the macros empty.  */
> > > -#  define OVERRIDE
> > > -#  define FINAL
> > > -# endif
> > > -#else
> > > -  /* No C++11 support; leave the macros empty.  */
> > > -# define OVERRIDE
> > > -# define FINAL
> > > -#endif
> > > -
> > >  /* A macro to disable the copy constructor and assignment
> > > operator.
> > >     When building with C++11 and above, the methods are
> > > explicitly
> > >     deleted, causing a compile-time error if something tries to
> > > copy.
> > 
> > 
>
diff mbox series

Patch

diff --git a/gcc/gcc-plugin.h b/gcc/gcc-plugin.h
index ee9aa865114..f0f3049d0ce 100644
--- a/gcc/gcc-plugin.h
+++ b/gcc/gcc-plugin.h
@@ -44,4 +44,11 @@  along with GCC; see the file COPYING3.  If not see
 #include "tree-check.h"
 #include "plugin.h"
 
+/* Versions of GCC prior to GCC 13 defined these macros in ansidecl.h
+   for C++98 compatibility.  Given that we require C++11 from GCC 11 onwards,
+   keep definitions here in case plugins made use of them.  */
+
+#define OVERRIDE override
+#define FINAL    final
+
 #endif /* GCC_PLUGIN_H */
diff --git a/include/ansidecl.h b/include/ansidecl.h
index efee5b6904b..119748deb68 100644
--- a/include/ansidecl.h
+++ b/include/ansidecl.h
@@ -345,47 +345,6 @@  So instead we use the macro below and test it against specific values.  */
 #define CONSTEXPR
 #endif
 
-/* C++11 adds the ability to add "override" after an implementation of a
-   virtual function in a subclass, to:
-     (A) document that this is an override of a virtual function
-     (B) allow the compiler to issue a warning if it isn't (e.g. a mismatch
-         of the type signature).
-
-   Similarly, it allows us to add a "final" to indicate that no subclass
-   may subsequently override the vfunc.
-
-   Provide OVERRIDE and FINAL as macros, allowing us to get these benefits
-   when compiling with C++11 support, but without requiring C++11.
-
-   For gcc, use "-std=c++11" to enable C++11 support; gcc 6 onwards enables
-   this by default (actually GNU++14).  */
-
-#if defined __cplusplus
-# if __cplusplus >= 201103
-   /* C++11 claims to be available: use it.  Final/override were only
-      implemented in 4.7, though.  */
-#  if GCC_VERSION < 4007
-#   define OVERRIDE
-#   define FINAL
-#  else
-#   define OVERRIDE override
-#   define FINAL final
-#  endif
-# elif GCC_VERSION >= 4007
-   /* G++ 4.7 supports __final in C++98.  */
-#  define OVERRIDE
-#  define FINAL __final
-# else
-   /* No C++11 support; leave the macros empty.  */
-#  define OVERRIDE
-#  define FINAL
-# endif
-#else
-  /* No C++11 support; leave the macros empty.  */
-# define OVERRIDE
-# define FINAL
-#endif
-
 /* A macro to disable the copy constructor and assignment operator.
    When building with C++11 and above, the methods are explicitly
    deleted, causing a compile-time error if something tries to copy.