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

Andy Furniss andyqos at ukfsn.org
Fri Aug 10 11:40:53 PDT 2012


Kenneth Graunke wrote:
> On 08/10/2012 07:51 AM, Chad Versace wrote:
>> On 08/09/2012 01:22 PM, Kenneth Graunke wrote:
>>> On 08/09/2012 01:10 PM, Chad Versace wrote:
>>>> Add -Wno-narrowing to CXXFLAGS for gcc.
>>>>
>>>> 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 of the form.  When building
>>>> i965, I observed no other difference in the build output.
>>>>
>>>> CC: Kenneth Graunke <kenneth at whitecape.org>
>>>> Signed-off-by: Chad Versace <chad.versace at linux.intel.com>
>>>> ---
>>>>   configure.ac | 3 +++
>>>>   1 file changed, 3 insertions(+)
>>>>
>>>> diff --git a/configure.ac b/configure.ac
>>>> index 89686b4..fa4fd71 100644
>>>> --- a/configure.ac
>>>> +++ b/configure.ac
>>>> @@ -228,6 +228,9 @@ if test "x$GXX" = xyes; then
>>>>       # gcc's builtin memcmp is slower than glibc's
>>>>       # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43052
>>>>       CXXFLAGS="$CXXFLAGS -fno-builtin-memcmp"
>>>> +
>>>> +    # Silence C++11 warnings that we don't care about.
>>>> +    CXXFLAGS="$CXXFLAGS -Wno-narrowing"
>>>>   fi
>>>>
>>>>   dnl even if the compiler appears to support it, using visibility attributes isn't
>>>
>>> Nak.  I believe this will break the build if using a g++ too old to
>>> recognize -Wno-narrowing.  You'd need to do the whole rigamarole used in
>>> the compiler flag checks a bit earlier.  Or import the handy m4 macro
>>> from xorg-util-macros which does all the rigamarole in one line.
>>
>> It's safe to do this. If an old gcc encounters a -Wno option that it does not
>> recognize, then it will usually silently ignore it. I verified this by building
>> with -Wno-whatever, and the option was silently ignored, as expected.
>>
>>  From the GCC Manual [http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html],
>> emphasis mine:
>>
>> When an unrecognized warning option is requested (e.g., -Wunknown-warning), GCC
>> emits a diagnostic stating that the option is not recognized. However, if the
>> -Wno- form is used, the behavior is slightly different: no diagnostic is
>> produced for -Wno-unknown-warning unless other diagnostics are being produced.
>> ***This allows the use of new -Wno- options with old compilers***, but if
>> something goes wrong, the compiler warns that an unrecognized option is present.
>
> Oh cool! :D
>
> I had no idea it did that.

Neither does my old gcc 4.2.3
make[2]: Entering directory `/home/andy/Src/Mesa-git/mesa/src/glsl'
g++ -DPACKAGE_NAME=\"Mesa\" -DPACKAGE_TARNAME=\"mesa\" 
-DPACKAGE_VERSION=\"8.1.0\" -DPACKAGE_STRING=\"Mesa\ 8.1.0\" 
-DPACKAGE_BUGREPORT=\"https://bugs.freedesktop.org/enter_bug.cgi\?product=Mesa\" 
-DPACKAGE_URL=\"\" -DPACKAGE=\"mesa\" -DVERSION=\"8.1.0\" 
-DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 
-DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 
-DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_DLFCN_H=1 
-DLT_OBJDIR=\".libs/\" -DYYTEXT_POINTER=1 -DHAVE_LIBEXPAT=1 -I. 
-I../../include -I../../src/mapi -I../../src/mesa/  -D_GNU_SOURCE 
-DPTHREADS -DDEBUG -DTEXTURE_FLOAT_ENABLED -DUSE_X86_ASM -DUSE_MMX_ASM 
-DUSE_3DNOW_ASM -DUSE_SSE_ASM -DHAVE_POSIX_MEMALIGN -DIN_DRI_DRIVER 
-DUSE_XCB -DGLX_INDIRECT_RENDERING -DGLX_DIRECT_RENDERING 
-DUSE_EXTERNAL_DXTN_LIB=1 -DIN_DRI_DRIVER -DHAVE_ALIAS 
-DHAVE_LLVM=0x0301  -DFEATURE_GL=1 -g -O2 -Wall -fno-strict-aliasing 
-fno-builtin-memcmp -Wno-narrowing -g  -MT standalone_scaffolding.o -MD 
-MP -MF .deps/standalone_scaffolding.Tpo -c -o standalone_scaffolding.o 
`test -f '../../src/glsl/standalone_scaffolding.cpp' || echo 
'./'`../../src/glsl/standalone_scaffolding.cpp
cc1plus: error: unrecognized command line option "-Wno-narrowing"
make[2]: *** [standalone_scaffolding.o] Error 1
make[2]: Leaving directory `/home/andy/Src/Mesa-git/mesa/src/glsl'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/andy/Src/Mesa-git/mesa/src'
make: *** [all-recursive] Error 1





More information about the mesa-dev mailing list