[Mesa-dev] [PATCH] mesa: Fix some -Wnarrowing warnings

Eric Anholt eric at anholt.net
Fri Aug 10 09:16:13 PDT 2012


Chad Versace <chad.versace at linux.intel.com> writes:

> Fixes the following warnings:
>   ff_fragment_shader.cpp: In function 'ir_rvalue* emit_texenv(texenv_fragment_program*, GLuint)':
>   ff_fragment_shader.cpp:897:3: warning: narrowing conversion of '(1 << ((int)rgb_shift))' from 'int' to 'float' inside { } is ill-formed in C++11 [-Wnarrowing]
>   ff_fragment_shader.cpp:897:3: warning: narrowing conversion of '(1 << ((int)rgb_shift))' from 'int' to 'float' inside { } is ill-formed in C++11 [-Wnarrowing]
>   ff_fragment_shader.cpp:897:3: warning: narrowing conversion of '(1 << ((int)rgb_shift))' from 'int' to 'float' inside { } is ill-formed in C++11 [-Wnarrowing]
>   ff_fragment_shader.cpp:897:3: warning: narrowing conversion of '(1 << ((int)alpha_shift))' from 'int' to 'float' inside { } is ill-formed in C++11 [-Wnarrowing]
>
> CC: Josh Triplett <josh at joshtriplett.org>
> Signed-off-by: Chad Versace <chad.versace at linux.intel.com>
> ---
>  src/mesa/main/ff_fragment_shader.cpp | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/src/mesa/main/ff_fragment_shader.cpp b/src/mesa/main/ff_fragment_shader.cpp
> index f743ce1..aefd412 100644
> --- a/src/mesa/main/ff_fragment_shader.cpp
> +++ b/src/mesa/main/ff_fragment_shader.cpp
> @@ -890,10 +890,10 @@ emit_texenv(struct texenv_fragment_program *p, GLuint unit)
>        }
>        else {
>  	 float const_data[4] = {
> -	    1 << rgb_shift,
> -	    1 << rgb_shift,
> -	    1 << rgb_shift,
> -	    1 << alpha_shift
> +	   static_cast<float>(1 << rgb_shift),
> +	   static_cast<float>(1 << rgb_shift),
> +	   static_cast<float>(1 << rgb_shift),
> +	   static_cast<float>(1 << alpha_shift)

So, what's wrong with
           (float)(1 << rgb_shift)
?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20120810/432bb3d6/attachment.pgp>


More information about the mesa-dev mailing list