bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: RFC: maint: c++: use nullptr for C++11


From: Akim Demaille
Subject: Re: RFC: maint: c++: use nullptr for C++11
Date: Sat, 31 Mar 2012 14:51:35 +0200

Le 31 mars 2012 à 11:20, Akim Demaille a écrit :

> Thanks!  I have done that in the patch I installed in maint
> (attached).  There is one issue to cover: G++ will happily
> complain about 0 instead of nullptr even when it does not
> declare it is C++11 via __cplusplus.  I will change configure.ac
> to use the corresponding warning only when the compiler does
> conform to the standard value of __cplusplus.

I thought I had a solution which seemed to be good enough:
use nullptr when supported by G++:

> diff --git a/data/c.m4 b/data/c.m4
> index 195c441..9f1f82d 100644
> --- a/data/c.m4
> +++ b/data/c.m4
> @@ -157,8 +157,15 @@ m4_define([b4_table_value_equals],
> # Portability issues: define a YY_NULL appropriate for the current
> # language (C, C++98, or C++11).
> m4_define([b4_null_define],
> -[# ifndef YY_NULL
> -#  if defined __cplusplus && 201103L <= __cplusplus
> +[/* Whether this is GCC at least Major.Minor.  */
> +# define YY_GCC(Major, Minor)                           \
> +  (defined __GNUC__                                     \
> +   && (Major < __GNUC__                                 \
> +       || (Major == __GNUC__ && Minor <= __GNUC_MINOR__)))
> +
> +/* Null pointer literal.  */
> +# ifndef YY_NULL
> +#  if defined __cplusplus && (201103L <= __cplusplus || YY_GCC(4, 6))
> #   define YY_NULL nullptr
> #  else
> #   define YY_NULL 0


Unfortunately, G++ can complain about using 0 even
when it does not support nullptr :(

> $ cat foo.cc
> int *p1 = 0;
> int *p2 = nullptr;
> 
> $ g++-mp-4.7 -Wzero-as-null-pointer-constant /tmp/foo.cc
> /tmp/foo.cc:1:11: warning: zero as null pointer constant 
> [-Wzero-as-null-pointer-constant]
> /tmp/foo.cc:2:11: error: 'nullptr' was not declared in this scope

I filed a bug report, and I really need to write
some Autoconf to use this warning only when the
compiler is set to support C++11.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]