===================================================================
@@ -2365,17 +2365,16 @@ an instance of a derived class through a pointer t
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++0x, suppress the diagnostic required by the standard for
-narrowing conversions within @samp{@{ @}}, e.g.
+Warn when a narrowing conversion 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++0x mode
+This flag is included in @option{-Wc++0x-compat}.
@item -Wnoexcept @r{(C++ and Objective-C++ only)}
@opindex Wnoexcept
@@ -2993,7 +2992,6 @@ Options} and @ref{Objective-C and Objective-C++ Di
@gccoptlist{-Waddress @gol
-Warray-bounds @r{(only with} @option{-O2}@r{)} @gol
--Wc++0x-compat @gol
-Wchar-subscripts @gol
-Wenum-compare @r{(in C/Objc; this is on by default in C++)} @gol
-Wimplicit-int @r{(C and Objective-C only)} @gol
@@ -4066,7 +4064,7 @@ ISO C and ISO C++, e.g.@: request for implicit con
@item -Wc++0x-compat @r{(C++ and Objective-C++ only)}
Warn about C++ constructs whose meaning differs between ISO C++ 1998 and
ISO C++ 200x, e.g., identifiers in ISO C++ 1998 that will become keywords
-in ISO C++ 200x. This warning is enabled by @option{-Wall}.
+in ISO C++ 200x. This warning turns on @option{-Wnarrowing}.
@item -Wcast-qual
@opindex Wcast-qual
===================================================================
@@ -490,8 +490,8 @@ C ObjC C++ ObjC++ Warning
Warn about use of multi-character character constants
Wnarrowing
-C ObjC C++ ObjC++ Warning Var(warn_narrowing) Init(1)
--Wno-narrowing In C++0x mode, ignore ill-formed narrowing conversions within { }
+C ObjC C++ ObjC++ Warning Var(warn_narrowing) Init(-1) Warning
+Warn about ill-formed narrowing conversions within { }
Wnested-externs
C ObjC Var(warn_nested_externs) Warning
===================================================================
@@ -404,7 +404,6 @@ c_common_handle_option (size_t scode, const char *
/* C++-specific warnings. */
warn_sign_compare = value;
warn_reorder = value;
- warn_cxx0x_compat = value;
warn_delnonvdtor = value;
}
@@ -436,6 +435,10 @@ c_common_handle_option (size_t scode, const char *
cpp_opts->warn_cxx_operator_names = value;
break;
+ case OPT_Wc__0x_compat:
+ warn_narrowing = value;
+ break;
+
case OPT_Wdeprecated:
cpp_opts->cpp_warn_deprecated = value;
break;
@@ -997,10 +1000,15 @@ c_common_post_options (const char **pfilename)
if (warn_implicit_function_declaration == -1)
warn_implicit_function_declaration = flag_isoc99;
- /* If we're allowing C++0x constructs, don't warn about C++0x
- compatibility problems. */
if (cxx_dialect == cxx0x)
- warn_cxx0x_compat = 0;
+ {
+ /* If we're allowing C++0x constructs, don't warn about C++98
+ identifiers which are keywords in C++0x. */
+ warn_cxx0x_compat = 0;
+ warn_narrowing = 1;
+ }
+ else if (warn_narrowing == -1)
+ warn_narrowing = 0;
if (flag_preprocess_only)
{
===================================================================
@@ -0,0 +1,5 @@
+// PR c++/50810
+// { dg-options "-std=gnu++98 -Wc++0x-compat" }
+
+int i;
+float data[] = { i }; // { dg-warning "narrowing" }
===================================================================
@@ -0,0 +1,5 @@
+// PR c++/50810
+// { dg-options "-std=gnu++98 -Wc++0x-compat -Wno-narrowing" }
+
+int i;
+float data[] = { i };
===================================================================
@@ -2,4 +2,4 @@
// { dg-options "-std=c++0x -pedantic-errors -Wno-narrowing" }
int i;
-float d = { i };
+float d = { i }; // { dg-error "narrowing" }
===================================================================
@@ -5523,7 +5523,7 @@ check_initializer (tree decl, tree init, int flags
else
{
init = reshape_init (type, init, tf_warning_or_error);
- if (cxx_dialect >= cxx0x && SCALAR_TYPE_P (type))
+ if (SCALAR_TYPE_P (type))
check_narrowing (type, init);
}
}
===================================================================
@@ -803,8 +803,10 @@ check_narrowing (tree type, tree init)
}
if (!ok)
- pedwarn (input_location, OPT_Wnarrowing, "narrowing conversion of %qE "
- "from %qT to %qT inside { }", init, ftype, type);
+ emit_diagnostic ((cxx_dialect != cxx98) ? DK_PEDWARN : DK_WARNING,
+ input_location, OPT_Wnarrowing,
+ "narrowing conversion of %qE from %qT to %qT inside { }",
+ init, ftype, type);
}
/* Process the initializer INIT for a variable of type TYPE, emitting
@@ -901,7 +903,7 @@ digest_init_r (tree type, tree init, bool nested,
{
tree *exp;
- if (cxx_dialect != cxx98 && nested)
+ if (nested)
check_narrowing (type, init);
init = convert_for_initialization (0, type, init, flags,
ICR_INIT, NULL_TREE, 0,
===================================================================
@@ -2369,7 +2369,7 @@ finish_compound_literal (tree type, tree compound_
&& check_array_initializer (NULL_TREE, type, compound_literal))
return error_mark_node;
compound_literal = reshape_init (type, compound_literal, complain);
- if (cxx_dialect >= cxx0x && SCALAR_TYPE_P (type)
+ if (SCALAR_TYPE_P (type)
&& !BRACE_ENCLOSED_INITIALIZER_P (compound_literal))
check_narrowing (type, compound_literal);
if (TREE_CODE (type) == ARRAY_TYPE