From 25339f1097a119662a4989964f32143ad44edbd3 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Wed, 2 Nov 2011 16:16:43 -0400 Subject: re PR c++/50810 (c++0x-compat does not warn about narrowing conversions) PR c++/50810 gcc/c-family * c-opts.c (c_common_handle_option): Enable -Wnarrowing as part of -Wall; include -Wnarrowing in -Wc++0x-compat; adjust default Wnarrowing for C++0x and C++98. * c.opt ([Wnarrowing]): Update. gcc/cp * typeck2.c (check_narrowing): Adjust OPT_Wnarrowing diagnostics. (digest_init_r): Call check_narrowing irrespective of the C++ dialect. * decl.c (check_initializer): Likewise. * semantics.c (finish_compound_literal): Likewise. gcc/ * configure.ac: Add -Wno-narrowing to warning options. libcpp/ * configure.ac: Add -Wno-narrowing to warning options. From-SVN: r180794 --- gcc/doc/invoke.texi | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'gcc/doc') diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index b68f607..d6c1faf 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -2363,17 +2363,22 @@ an instance of a derived class through a pointer to a base class if the base class does not have a virtual destructor. This warning is enabled by @option{-Wall}. -@item -Wno-narrowing @r{(C++ and Objective-C++ only)} +@item -Wnarrowing @r{(C++ and Objective-C++ only)} @opindex Wnarrowing @opindex Wno-narrowing -With -std=c++11, suppress the diagnostic required by the standard for -narrowing conversions within @samp{@{ @}}, e.g. +Warn when a narrowing conversion prohibited by C++11 occurs within +@samp{@{ @}}, e.g. @smallexample int i = @{ 2.2 @}; // error: narrowing from double to int @end smallexample -This flag can be useful for compiling valid C++98 code in C++11 mode. +This flag is included in @option{-Wall} and @option{-Wc++11-compat}. + +With -std=c++11, @option{-Wno-narrowing} suppresses the diagnostic +required by the standard. Note that this does not affect the meaning +of well-formed code; narrowing conversions are still considered +ill-formed in SFINAE context. @item -Wnoexcept @r{(C++ and Objective-C++ only)} @opindex Wnoexcept @@ -4062,9 +4067,10 @@ ISO C and ISO C++, e.g.@: request for implicit conversion from @code{void *} to a pointer to non-@code{void} type. @item -Wc++11-compat @r{(C++ and Objective-C++ only)} -Warn about C++ constructs whose meaning differs between ISO C++ 1998 and -ISO C++ 2011, e.g., identifiers in ISO C++ 1998 that will become keywords -in ISO C++ 2011. This warning is enabled by @option{-Wall}. +Warn about C++ constructs whose meaning differs between ISO C++ 1998 +and ISO C++ 2011, e.g., identifiers in ISO C++ 1998 that are keywords +in ISO C++ 2011. This warning turns on @option{-Wnarrowing} and is +enabled by @option{-Wall}. @item -Wcast-qual @opindex Wcast-qual -- cgit v1.1