* [C++ Patch] PR 50810
@ 2011-10-23 15:02 Paolo Carlini
2011-10-23 17:31 ` Jason Merrill
0 siblings, 1 reply; 6+ messages in thread
From: Paolo Carlini @ 2011-10-23 15:02 UTC (permalink / raw)
To: gcc-patches; +Cc: Jason Merrill
[-- Attachment #1: Type: text/plain, Size: 188 bytes --]
Hi,
this is essentially about enabling -Wnarrowing as part of -Wc++0x-compat
(see audit trail for details). Tested x86_64-linux.
Ok for mainline?
Thanks,
Paolo.
/////////////////////
[-- Attachment #2: CL_50810 --]
[-- Type: text/plain, Size: 955 bytes --]
/c-family
2011-10-23 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/50810
* 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]): Adjust.
/cp
2011-10-23 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/50810
* 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.
/testsuite
2011-10-23 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/50810
* g++.dg/cpp0x/warn_cxx0x.C: Rename to...
* g++.dg/cpp0x/warn_cxx0x1.C: ... this.
* g++.dg/cpp0x/warn_cxx0x2.C: New.
* g++.dg/cpp0x/warn_cxx0x3.C: Likewise.
2011-10-23 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/50810
* doc/invoke.texi ([-Wnarrowing], [-Wc++0x-compat]): Update.
[-- Attachment #3: patch_50810 --]
[-- Type: text/plain, Size: 6680 bytes --]
Index: doc/invoke.texi
===================================================================
--- doc/invoke.texi (revision 180333)
+++ doc/invoke.texi (working copy)
@@ -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{-Wall} and @option{-Wc++0x-compat}.
@item -Wnoexcept @r{(C++ and Objective-C++ only)}
@opindex Wnoexcept
@@ -4066,7 +4065,8 @@ 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} and is
+enabled by @option{-Wall}.
@item -Wcast-qual
@opindex Wcast-qual
Index: c-family/c.opt
===================================================================
--- c-family/c.opt (revision 180333)
+++ c-family/c.opt (working copy)
@@ -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
Index: c-family/c-opts.c
===================================================================
--- c-family/c-opts.c (revision 180333)
+++ c-family/c-opts.c (working copy)
@@ -406,6 +406,7 @@ c_common_handle_option (size_t scode, const char *
warn_reorder = value;
warn_cxx0x_compat = value;
warn_delnonvdtor = value;
+ warn_narrowing = value;
}
cpp_opts->warn_trigraphs = value;
@@ -436,6 +437,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,11 +1002,18 @@ 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;
+ if (warn_narrowing == -1)
+ warn_narrowing = 1;
+ }
+ else if (warn_narrowing == -1)
+ warn_narrowing = 0;
+
if (flag_preprocess_only)
{
/* Open the output now. We must do so even if flag_no_output is
Index: testsuite/g++.dg/cpp0x/warn_cxx0x2.C
===================================================================
--- testsuite/g++.dg/cpp0x/warn_cxx0x2.C (revision 0)
+++ testsuite/g++.dg/cpp0x/warn_cxx0x2.C (revision 0)
@@ -0,0 +1,4 @@
+// PR c++/50810
+// { dg-options "-std=gnu++98 -Wc++0x-compat" }
+
+signed char data[] = { 0xff }; // { dg-warning "narrowing" }
Index: testsuite/g++.dg/cpp0x/warn_cxx0x3.C
===================================================================
--- testsuite/g++.dg/cpp0x/warn_cxx0x3.C (revision 0)
+++ testsuite/g++.dg/cpp0x/warn_cxx0x3.C (revision 0)
@@ -0,0 +1,4 @@
+// PR c++/50810
+// { dg-options "-std=gnu++98 -Wc++0x-compat -Wno-narrowing" }
+
+signed char data[] = { 0xff };
Index: testsuite/g++.dg/cpp0x/warn_cxx0x.C
===================================================================
--- testsuite/g++.dg/cpp0x/warn_cxx0x.C (revision 180333)
+++ testsuite/g++.dg/cpp0x/warn_cxx0x.C (working copy)
@@ -1,9 +0,0 @@
-// { dg-options "-std=gnu++98 -Wc++0x-compat" }
-int static_assert; // { dg-warning "will become a keyword" }
-int nullptr; // { dg-warning "will become a keyword" }
-
-void foo()
-{
- static_assert = 5;
- nullptr = 5;
-}
Index: cp/decl.c
===================================================================
--- cp/decl.c (revision 180333)
+++ cp/decl.c (working copy)
@@ -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);
}
}
Index: cp/typeck2.c
===================================================================
--- cp/typeck2.c (revision 180333)
+++ cp/typeck2.c (working copy)
@@ -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,
Index: cp/semantics.c
===================================================================
--- cp/semantics.c (revision 180333)
+++ cp/semantics.c (working copy)
@@ -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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [C++ Patch] PR 50810
2011-10-23 15:02 [C++ Patch] PR 50810 Paolo Carlini
@ 2011-10-23 17:31 ` Jason Merrill
2011-10-23 19:05 ` Paolo Carlini
0 siblings, 1 reply; 6+ messages in thread
From: Jason Merrill @ 2011-10-23 17:31 UTC (permalink / raw)
To: Paolo Carlini; +Cc: gcc-patches
On 10/23/2011 07:23 AM, Paolo Carlini wrote:
> -@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{-Wall} and @option{-Wc++0x-compat}.
Please still also talk about using -Wno-narrowing in C++0x mode here.
> * g++.dg/cpp0x/warn_cxx0x.C: Rename to...
> * g++.dg/cpp0x/warn_cxx0x1.C: ... this.
I wouldn't bother renaming, you can just add the new tests.
Jason
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [C++ Patch] PR 50810
2011-10-23 17:31 ` Jason Merrill
@ 2011-10-23 19:05 ` Paolo Carlini
2011-10-23 20:07 ` Jason Merrill
0 siblings, 1 reply; 6+ messages in thread
From: Paolo Carlini @ 2011-10-23 19:05 UTC (permalink / raw)
To: Jason Merrill; +Cc: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 808 bytes --]
Hi,
> On 10/23/2011 07:23 AM, Paolo Carlini wrote:
>> -@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{-Wall} and @option{-Wc++0x-compat}.
>
> Please still also talk about using -Wno-narrowing in C++0x mode here.
I change it like this. Better?
Thanks,
Paolo.
///////////////////
[-- Attachment #2: CL_50810_2 --]
[-- Type: text/plain, Size: 871 bytes --]
/c-family
2011-10-23 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/50810
* 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.
/cp
2011-10-23 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/50810
* 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.
/testsuite
2011-10-23 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/50810
* g++.dg/cpp0x/warn_cxx0x2.C: New.
* g++.dg/cpp0x/warn_cxx0x3.C: Likewise.
2011-10-23 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/50810
* doc/invoke.texi ([-Wnarrowing], [-Wc++0x-compat]): Update.
[-- Attachment #3: patch_50810_2 --]
[-- Type: text/plain, Size: 6311 bytes --]
Index: doc/invoke.texi
===================================================================
--- doc/invoke.texi (revision 180333)
+++ doc/invoke.texi (working copy)
@@ -2365,17 +2365,18 @@ 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.
+With -std=c++0x, @option{-Wno-narrowing} suppresses the diagnostic
+required by the standard. This flag is included in @option{-Wall} and
+@option{-Wc++0x-compat}.
@item -Wnoexcept @r{(C++ and Objective-C++ only)}
@opindex Wnoexcept
@@ -4066,7 +4067,8 @@ 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} and is
+enabled by @option{-Wall}.
@item -Wcast-qual
@opindex Wcast-qual
Index: c-family/c.opt
===================================================================
--- c-family/c.opt (revision 180333)
+++ c-family/c.opt (working copy)
@@ -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
Index: c-family/c-opts.c
===================================================================
--- c-family/c-opts.c (revision 180333)
+++ c-family/c-opts.c (working copy)
@@ -406,6 +406,7 @@ c_common_handle_option (size_t scode, const char *
warn_reorder = value;
warn_cxx0x_compat = value;
warn_delnonvdtor = value;
+ warn_narrowing = value;
}
cpp_opts->warn_trigraphs = value;
@@ -436,6 +437,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,11 +1002,18 @@ 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;
+ if (warn_narrowing == -1)
+ warn_narrowing = 1;
+ }
+ else if (warn_narrowing == -1)
+ warn_narrowing = 0;
+
if (flag_preprocess_only)
{
/* Open the output now. We must do so even if flag_no_output is
Index: testsuite/g++.dg/cpp0x/warn_cxx0x2.C
===================================================================
--- testsuite/g++.dg/cpp0x/warn_cxx0x2.C (revision 0)
+++ testsuite/g++.dg/cpp0x/warn_cxx0x2.C (revision 0)
@@ -0,0 +1,4 @@
+// PR c++/50810
+// { dg-options "-std=gnu++98 -Wc++0x-compat" }
+
+signed char data[] = { 0xff }; // { dg-warning "narrowing" }
Index: testsuite/g++.dg/cpp0x/warn_cxx0x3.C
===================================================================
--- testsuite/g++.dg/cpp0x/warn_cxx0x3.C (revision 0)
+++ testsuite/g++.dg/cpp0x/warn_cxx0x3.C (revision 0)
@@ -0,0 +1,4 @@
+// PR c++/50810
+// { dg-options "-std=gnu++98 -Wc++0x-compat -Wno-narrowing" }
+
+signed char data[] = { 0xff };
Index: cp/decl.c
===================================================================
--- cp/decl.c (revision 180333)
+++ cp/decl.c (working copy)
@@ -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);
}
}
Index: cp/typeck2.c
===================================================================
--- cp/typeck2.c (revision 180333)
+++ cp/typeck2.c (working copy)
@@ -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,
Index: cp/semantics.c
===================================================================
--- cp/semantics.c (revision 180333)
+++ cp/semantics.c (working copy)
@@ -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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [C++ Patch] PR 50810
2011-10-23 19:05 ` Paolo Carlini
@ 2011-10-23 20:07 ` Jason Merrill
2011-11-02 20:14 ` Jason Merrill
0 siblings, 1 reply; 6+ messages in thread
From: Jason Merrill @ 2011-10-23 20:07 UTC (permalink / raw)
To: Paolo Carlini; +Cc: gcc-patches
On 10/23/2011 11:00 AM, Paolo Carlini wrote:
> +With -std=c++0x, @option{-Wno-narrowing} suppresses the diagnostic
> +required by the standard. This flag is included in @option{-Wall} and
> +@option{-Wc++0x-compat}.
I'd swap those two sentences. OK with that change.
Jason
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [C++ Patch] PR 50810
2011-10-23 20:07 ` Jason Merrill
@ 2011-11-02 20:14 ` Jason Merrill
2011-11-02 20:30 ` Paolo Carlini
0 siblings, 1 reply; 6+ messages in thread
From: Jason Merrill @ 2011-11-02 20:14 UTC (permalink / raw)
To: Paolo Carlini; +Cc: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 218 bytes --]
I'm checking in this variant of your patch; mostly it just adds
-Wno-narrowing to the warning options used to build GCC, though there
are a few wording tweaks as well.
Tested x86_64-pc-linux-gnu, applying to trunk.
[-- Attachment #2: 50810.patch --]
[-- Type: text/x-patch, Size: 9748 bytes --]
commit 6b5380306428a3e618027b3fc7a319ae2c520b35
Author: Jason Merrill <jason@redhat.com>
Date: Tue Nov 1 11:56:30 2011 -0400
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.
diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c
index b56aec7..465bce3 100644
--- a/gcc/c-family/c-opts.c
+++ b/gcc/c-family/c-opts.c
@@ -406,6 +406,7 @@ c_common_handle_option (size_t scode, const char *arg, int value,
warn_reorder = value;
warn_cxx0x_compat = value;
warn_delnonvdtor = value;
+ warn_narrowing = value;
}
cpp_opts->warn_trigraphs = value;
@@ -436,6 +437,10 @@ c_common_handle_option (size_t scode, const char *arg, int value,
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 +1002,17 @@ 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;
+
+ if (warn_narrowing == -1)
+ warn_narrowing = 1;
+ }
+ else if (warn_narrowing == -1)
+ warn_narrowing = 0;
if (flag_preprocess_only)
{
diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 438b8b0..0d7dc88 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -494,8 +494,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)
+Warn about narrowing conversions within { } that are ill-formed in C++11
Wnested-externs
C ObjC Var(warn_nested_externs) Warning
diff --git a/gcc/configure b/gcc/configure
index 3b0b39b..35dbdd8 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -6394,11 +6394,12 @@ fi
# * 'long long'
# * variadic macros
# * overlong strings
+# * C++11 narrowing conversions in { }
# So, we only use -pedantic if we can disable those warnings.
loose_warn=
save_CFLAGS="$CFLAGS"
-for option in -W -Wall -Wwrite-strings -Wcast-qual; do
+for option in -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual; do
as_acx_Woption=`$as_echo "acx_cv_prog_cc_warning_$option" | $as_tr_sh`
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports $option" >&5
diff --git a/gcc/configure.ac b/gcc/configure.ac
index dd6cf2f..9196996 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -329,10 +329,11 @@ GCC_STDINT_TYPES
# * 'long long'
# * variadic macros
# * overlong strings
+# * C++11 narrowing conversions in { }
# So, we only use -pedantic if we can disable those warnings.
ACX_PROG_CC_WARNING_OPTS(
- m4_quote(m4_do([-W -Wall -Wwrite-strings -Wcast-qual])), [loose_warn])
+ m4_quote(m4_do([-W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual])), [loose_warn])
ACX_PROG_CC_WARNING_OPTS(
m4_quote(m4_do([-Wstrict-prototypes -Wmissing-prototypes])),
[c_loose_warn])
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 860556c..edbc783 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -5538,7 +5538,7 @@ check_initializer (tree decl, tree init, int flags, tree *cleanup)
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);
}
}
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index d76df51..a80aec6 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -2369,7 +2369,7 @@ finish_compound_literal (tree type, tree compound_literal,
&& 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
diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c
index 57cd5e0..1b43449 100644
--- a/gcc/cp/typeck2.c
+++ b/gcc/cp/typeck2.c
@@ -804,8 +804,16 @@ 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);
+ {
+ if (cxx_dialect >= cxx0x)
+ pedwarn (EXPR_LOC_OR_HERE (init), OPT_Wnarrowing,
+ "narrowing conversion of %qE from %qT to %qT inside { }",
+ init, ftype, type);
+ else
+ warning_at (EXPR_LOC_OR_HERE (init), OPT_Wnarrowing,
+ "narrowing conversion of %qE from %qT to %qT inside { } "
+ "is ill-formed in C++11", init, ftype, type);
+ }
}
/* Process the initializer INIT for a variable of type TYPE, emitting
@@ -902,7 +910,7 @@ digest_init_r (tree type, tree init, bool nested, int flags,
{
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,
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
diff --git a/gcc/testsuite/g++.dg/cpp0x/warn_cxx0x2.C b/gcc/testsuite/g++.dg/cpp0x/warn_cxx0x2.C
new file mode 100644
index 0000000..116b233
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/warn_cxx0x2.C
@@ -0,0 +1,4 @@
+// PR c++/50810
+// { dg-options "-std=gnu++98 -Wc++11-compat" }
+
+signed char data[] = { 0xff }; // { dg-warning "narrowing" }
diff --git a/gcc/testsuite/g++.dg/cpp0x/warn_cxx0x3.C b/gcc/testsuite/g++.dg/cpp0x/warn_cxx0x3.C
new file mode 100644
index 0000000..c3df9d9
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/warn_cxx0x3.C
@@ -0,0 +1,4 @@
+// PR c++/50810
+// { dg-options "-std=gnu++98 -Wc++11-compat -Wno-narrowing" }
+
+signed char data[] = { 0xff };
diff --git a/libcpp/configure b/libcpp/configure
index c400d23..a26a477 100755
--- a/libcpp/configure
+++ b/libcpp/configure
@@ -4687,7 +4687,7 @@ test -n "$AUTOHEADER" || AUTOHEADER="$MISSING autoheader"
warn=
save_CFLAGS="$CFLAGS"
-for option in -W -Wall -Wwrite-strings \
+for option in -W -Wall -Wno-narrowing -Wwrite-strings \
-Wmissing-format-attribute; do
as_acx_Woption=`$as_echo "acx_cv_prog_cc_warning_$option" | $as_tr_sh`
diff --git a/libcpp/configure.ac b/libcpp/configure.ac
index e1d8851..e843768 100644
--- a/libcpp/configure.ac
+++ b/libcpp/configure.ac
@@ -33,7 +33,7 @@ AC_CHECK_PROGS([AUTOHEADER], [autoheader], [$MISSING autoheader])
# Figure out what compiler warnings we can enable.
# See config/warnings.m4 for details.
-ACX_PROG_CC_WARNING_OPTS([-W -Wall -Wwrite-strings \
+ACX_PROG_CC_WARNING_OPTS([-W -Wall -Wno-narrowing -Wwrite-strings \
-Wmissing-format-attribute], [warn])
ACX_PROG_CC_WARNING_OPTS([-Wstrict-prototypes -Wmissing-prototypes \
-Wold-style-definition -Wc++-compat], [c_warn])
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [C++ Patch] PR 50810
2011-11-02 20:14 ` Jason Merrill
@ 2011-11-02 20:30 ` Paolo Carlini
0 siblings, 0 replies; 6+ messages in thread
From: Paolo Carlini @ 2011-11-02 20:30 UTC (permalink / raw)
To: Jason Merrill; +Cc: gcc-patches
On 11/02/2011 09:11 PM, Jason Merrill wrote:
> I'm checking in this variant of your patch; mostly it just adds
> -Wno-narrowing to the warning options used to build GCC, though there
> are a few wording tweaks as well.
>
> Tested x86_64-pc-linux-gnu, applying to trunk.
Thanks!
Paolo.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2011-11-02 20:24 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-23 15:02 [C++ Patch] PR 50810 Paolo Carlini
2011-10-23 17:31 ` Jason Merrill
2011-10-23 19:05 ` Paolo Carlini
2011-10-23 20:07 ` Jason Merrill
2011-11-02 20:14 ` Jason Merrill
2011-11-02 20:30 ` Paolo Carlini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).