Remove legacy pre-C++ 11 definitions

Message ID 6defa548-2da3-6cba-0372-f1e6c6b64c81@suse.cz
State New
Headers
Series Remove legacy pre-C++ 11 definitions |

Commit Message

Martin Liška Jan. 6, 2023, 12:21 p.m. UTC
  As mentioned in the PRs, both are defined in C++ 11
which is a version we depend on.

Ready to be installed now?

Thanks,
Martin

	PR middle-end/108311
	PR middle-end/108312

gcc/ChangeLog:

	* system.h (va_copy): Remove as it is defined in C++ 11.
	(NULL): Likewise.
---
 gcc/system.h | 13 -------------
 1 file changed, 13 deletions(-)
  

Comments

Andrew Pinski Jan. 6, 2023, 5:21 p.m. UTC | #1
On Fri, Jan 6, 2023 at 4:21 AM Martin Liška <mliska@suse.cz> wrote:
>
> As mentioned in the PRs, both are defined in C++ 11
> which is a version we depend on.
>
> Ready to be installed now?

There is another #define NULL below:
/* System headers may define NULL to be an integer (e.g. 0L), which cannot be
   used safely in certain contexts (e.g. as sentinels).  Redefine NULL to
   nullptr in order to make it safer.  Note that this might confuse system
   headers, however, by convention they must not be included after this point.
*/
#ifdef __cplusplus
#undef NULL
#define NULL nullptr
#endif

Thanks,
Andrew Pinski

>
> Thanks,
> Martin
>
>         PR middle-end/108311
>         PR middle-end/108312
>
> gcc/ChangeLog:
>
>         * system.h (va_copy): Remove as it is defined in C++ 11.
>         (NULL): Likewise.
> ---
>  gcc/system.h | 13 -------------
>  1 file changed, 13 deletions(-)
>
> diff --git a/gcc/system.h b/gcc/system.h
> index 5eaeb9d2d03..0d06b9749e5 100644
> --- a/gcc/system.h
> +++ b/gcc/system.h
> @@ -31,25 +31,12 @@ along with GCC; see the file COPYING3.  If not see
>  /* We must include stdarg.h before stdio.h.  */
>  #include <stdarg.h>
>
> -#ifndef va_copy
> -# ifdef __va_copy
> -#   define va_copy(d,s)  __va_copy (d, s)
> -# else
> -#   define va_copy(d,s)  ((d) = (s))
> -# endif
> -#endif
> -
>  #ifdef HAVE_STDDEF_H
>  # include <stddef.h>
>  #endif
>
>  #include <stdio.h>
>
> -/* Define a generic NULL if one hasn't already been defined.  */
> -#ifndef NULL
> -#define NULL 0
> -#endif
> -
>  /* Use the unlocked open routines from libiberty.  */
>
>  /* Some of these are #define on some systems, e.g. on AIX to redirect
> --
> 2.39.0
>
  
Jonathan Wakely Jan. 6, 2023, 6:23 p.m. UTC | #2
On Fri, 6 Jan 2023, 17:21 Andrew Pinski, <pinskia@gmail.com> wrote:

> On Fri, Jan 6, 2023 at 4:21 AM Martin Liška <mliska@suse.cz> wrote:
> >
> > As mentioned in the PRs, both are defined in C++ 11
> > which is a version we depend on.
> >
> > Ready to be installed now?
>
> There is another #define NULL below:
> /* System headers may define NULL to be an integer (e.g. 0L), which cannot
> be
>    used safely in certain contexts (e.g. as sentinels).  Redefine NULL to
>    nullptr in order to make it safer.  Note that this might confuse system
>    headers, however, by convention they must not be included after this
> point.
> */
> #ifdef __cplusplus
> #undef NULL
> #define NULL nullptr
> #endif
>

Seems to me that GCC code should just use nullptr directly not redefine
NULL.


Thanks,
> Andrew Pinski
>
> >
> > Thanks,
> > Martin
> >
> >         PR middle-end/108311
> >         PR middle-end/108312
> >
> > gcc/ChangeLog:
> >
> >         * system.h (va_copy): Remove as it is defined in C++ 11.
> >         (NULL): Likewise.
> > ---
> >  gcc/system.h | 13 -------------
> >  1 file changed, 13 deletions(-)
> >
> > diff --git a/gcc/system.h b/gcc/system.h
> > index 5eaeb9d2d03..0d06b9749e5 100644
> > --- a/gcc/system.h
> > +++ b/gcc/system.h
> > @@ -31,25 +31,12 @@ along with GCC; see the file COPYING3.  If not see
> >  /* We must include stdarg.h before stdio.h.  */
> >  #include <stdarg.h>
> >
> > -#ifndef va_copy
> > -# ifdef __va_copy
> > -#   define va_copy(d,s)  __va_copy (d, s)
> > -# else
> > -#   define va_copy(d,s)  ((d) = (s))
> > -# endif
> > -#endif
> > -
> >  #ifdef HAVE_STDDEF_H
> >  # include <stddef.h>
> >  #endif
> >
> >  #include <stdio.h>
> >
> > -/* Define a generic NULL if one hasn't already been defined.  */
> > -#ifndef NULL
> > -#define NULL 0
> > -#endif
> > -
> >  /* Use the unlocked open routines from libiberty.  */
> >
> >  /* Some of these are #define on some systems, e.g. on AIX to redirect
> > --
> > 2.39.0
> >
>
  
Martin Liška Jan. 9, 2023, 3:17 p.m. UTC | #3
On 1/6/23 19:23, Jonathan Wakely wrote:
> Seems to me that GCC code should just use nullptr directly not redefine NULL.

Sure, but that would lead to a huge patch which would rename NULL to nullptr, right?

Martin
  
Jonathan Wakely Jan. 9, 2023, 3:19 p.m. UTC | #4
On Mon, 9 Jan 2023 at 15:17, Martin Liška <mliska@suse.cz> wrote:
>
> On 1/6/23 19:23, Jonathan Wakely wrote:
> > Seems to me that GCC code should just use nullptr directly not redefine NULL.
>
> Sure, but that would lead to a huge patch which would rename NULL to nullptr, right?


Yeah, which can probably be done separately (or not done at all). I
was just commenting on the comment that Andrew showed. That comment
explain that nullptr is better than 0 as a null pointer constant,
which is a good reason to prefer nullptr. But not a good reason to
redefine NULL; in code with a minimum requirement of C++11 you can
just use nullptr directly.
  
Martin Liška Jan. 10, 2023, 8:32 a.m. UTC | #5
On 1/9/23 16:19, Jonathan Wakely wrote:
> On Mon, 9 Jan 2023 at 15:17, Martin Liška <mliska@suse.cz> wrote:
>>
>> On 1/6/23 19:23, Jonathan Wakely wrote:
>>> Seems to me that GCC code should just use nullptr directly not redefine NULL.
>>
>> Sure, but that would lead to a huge patch which would rename NULL to nullptr, right?
> 
> 
> Yeah, which can probably be done separately (or not done at all).

That would be a massive patch affecting all targets and FEs.

> I was just commenting on the comment that Andrew showed. That comment
> explain that nullptr is better than 0 as a null pointer constant,
> which is a good reason to prefer nullptr. But not a good reason to
> redefine NULL; in code with a minimum requirement of C++11 you can
> just use nullptr directly.

Ok, so does it mean my patch addresses what can be easily adjusted?

Thanks,
Martin
  

Patch

diff --git a/gcc/system.h b/gcc/system.h
index 5eaeb9d2d03..0d06b9749e5 100644
--- a/gcc/system.h
+++ b/gcc/system.h
@@ -31,25 +31,12 @@  along with GCC; see the file COPYING3.  If not see
 /* We must include stdarg.h before stdio.h.  */
 #include <stdarg.h>
 
-#ifndef va_copy
-# ifdef __va_copy
-#   define va_copy(d,s)  __va_copy (d, s)
-# else
-#   define va_copy(d,s)  ((d) = (s))
-# endif
-#endif
-
 #ifdef HAVE_STDDEF_H
 # include <stddef.h>
 #endif
 
 #include <stdio.h>
 
-/* Define a generic NULL if one hasn't already been defined.  */
-#ifndef NULL
-#define NULL 0
-#endif
-
 /* Use the unlocked open routines from libiberty.  */
 
 /* Some of these are #define on some systems, e.g. on AIX to redirect