[Mesa-dev] [PATCH] mesa: Remove C++11 narrowing warnings

Matt Turner mattst88 at gmail.com
Mon Aug 20 14:17:11 PDT 2012


On Mon, Aug 20, 2012 at 1:52 PM, Chad Versace
<chad.versace at linux.intel.com> wrote:
> Add -Wno-narrowing to CXXFLAGS if gcc supports it.
>
> This removes warnings of the form
>     warning: narrowing conversion of X from 'int' to 'float' inside { } is
>     ill-formed in C++11 [-Wnarrowing]
> in ff_fragment_shader.cpp and gen6_blorp.cpp. When building i965,
> I observed no other difference in the build output.
>
> CC: Kenneth Graunke <kenneth at whitecape.org>
> CC: Matthew Turner <matts88 at gmail.com>
> Signed-off-by: Chad Versace <chad.versace at linux.intel.com>
> ---
>  configure.ac | 13 ++++++++++++-
>  1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/configure.ac b/configure.ac
> index fcfe085..89b8fe7 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -219,7 +219,17 @@ if test "x$GXX" = xyes; then
>                    [VISIBILITY_CXXFLAGS="" ; AC_MSG_RESULT([no])]);
>      AC_LANG_POP([C++])
>
> -    # Restore CXXFLAGS; VISIBILITY_CXXFLAGS are added to it where needed.
> +    # Enable -Wno-narrowing if using a gcc that supports it.
> +    save_CXXFLAGS="$CXXFLAGS"
> +    WNO_NARROWING_CXXFLAGS="-Wno-narrowing"
> +    AC_MSG_CHECKING([whether $CXX supports $WNO_NARROWING_CXXFLAGS])
> +    CXXFLAGS="$CXXFLAGS $WNO_NARROWING_CXXFLAGS"
> +    AC_LANG_PUSH([C++])
> +    AC_LINK_IFELSE([AC_LANG_PROGRAM()], AC_MSG_RESULT([yes]),
> +                  [WNO_NARROWING_CXXFLAGS="" ; AC_MSG_RESULT([no])]);
> +    AC_LANG_POP([C++])
> +
> +    # Restore CXXFLAGS. The flags probed above are added where needed.
>      CXXFLAGS=$save_CXXFLAGS
>
>      # Work around aliasing bugs - developers should comment this out
> @@ -244,6 +254,7 @@ esac
>
>  AC_SUBST([VISIBILITY_CFLAGS])
>  AC_SUBST([VISIBILITY_CXXFLAGS])
> +AC_SUBST([WNO_NARROWING_CXXFLAGS])
>
>  dnl
>  dnl Hacks to enable 32 or 64 bit build
> --
> 1.7.11.4

I can't see how the VISIBILITY_CFLAGS are getting added to the build.
It looks like we somehow lost their uses -- which means the narrowing
flag also isn't being added to the build. To do this you either add it
to the Makefile.am's (via AM_CXXFLAGS) or directly to CXXFLAGS.

I think we're doing the right thing here and setting the flags in
their own variables (as opposed to appending to C(XX)FLAGS). The
automake manual recommends this:
http://www.gnu.org/software/automake/manual/automake.html#User-Variables


More information about the mesa-dev mailing list