Re: [C++ Patch] PR 50810

2011-11-02 Thread Jason Merrill
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.
commit 6b5380306428a3e618027b3fc7a319ae2c520b35
Author: Jason Merrill ja...@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 

Re: [C++ Patch] PR 50810

2011-11-02 Thread Paolo Carlini

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.


Re: [C++ Patch] PR 50810 (new try)

2011-10-24 Thread Gabriel Dos Reis
On Mon, Oct 24, 2011 at 6:47 AM, Paolo Carlini paolo.carl...@oracle.com wrote:
 Hi,

 the below is a new variant removing -Wc++0x-compat from -Wall (cannot be
 added to -Wextra either because bootstrap passes -W) and also, as requested
 by Gaby, preventing -Wno-narrowing from suppressing the warning in C++0x
 mode (if the user really needs to silence it, -Wno-c++0x-compat works). I
 also added a new testcase for that.


OK with a minor correction.  This bit

+With -std=c++0x, @option{-Wno-c++0x-compat} can be used to suppress
+the diagnostic required by the standard.

should not be there.  It is currently an accident of implementation
detail as opposed to a feature.  It needs no advertisement.


Re: [C++ Patch] PR 50810 (new try)

2011-10-24 Thread Paolo Carlini

Hi,

On Mon, Oct 24, 2011 at 6:47 AM, Paolo Carlinipaolo.carl...@oracle.com  wrote:

Hi,

the below is a new variant removing -Wc++0x-compat from -Wall (cannot be
added to -Wextra either because bootstrap passes -W) and also, as requested
by Gaby, preventing -Wno-narrowing from suppressing the warning in C++0x
mode (if the user really needs to silence it, -Wno-c++0x-compat works). I
also added a new testcase for that.


OK with a minor correction.  This bit

+With -std=c++0x, @option{-Wno-c++0x-compat} can be used to suppress
+the diagnostic required by the standard.

should not be there.  It is currently an accident of implementation
detail as opposed to a feature.  It needs no advertisement.
Ok. But I actively made it possible, if you want I can remove the 
possibility altogether, the patch also becomes cleaner ;)


Paolo.


Re: [C++ Patch] PR 50810 (new try)

2011-10-24 Thread Paolo Carlini

On 10/24/2011 02:18 PM, Paolo Carlini wrote:

OK with a minor correction.  This bit

+With -std=c++0x, @option{-Wno-c++0x-compat} can be used to suppress
+the diagnostic required by the standard.

should not be there.  It is currently an accident of implementation
detail as opposed to a feature.  It needs no advertisement.


Ok. But I actively made it possible, if you want I can remove the 
possibility altogether, the patch also becomes cleaner ;)

I can boot  test the below, in other terms.

Paolo.


/c-family
2011-10-24  Paolo Carlini  paolo.carl...@oracle.com

PR c++/50810
* c-opts.c (c_common_handle_option): Do not enable -Wc++0x-compat
as part of -Wall; handle -Wc++0x-compat.
(c_common_post_options): -std=c++0x enables -Wnarrowing.
* c.opt ([Wnarrowing]): Update.

/cp
2011-10-24  Paolo Carlini  paolo.carl...@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-24  Paolo Carlini  paolo.carl...@oracle.com

PR c++/50810
* g++.dg/cpp0x/warn_cxx0x2.C: New.
* g++.dg/cpp0x/warn_cxx0x3.C: Likewise.
* g++.dg/cpp0x/initlist55.C: Adjust.

2011-10-24  Paolo Carlini  paolo.carl...@oracle.com

PR c++/50810
* doc/invoke.texi ([-Wall], [-Wnarrowing], [-Wc++0x-compat]): Update.
Index: doc/invoke.texi
===
--- doc/invoke.texi (revision 180373)
+++ 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{-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
Index: c-family/c.opt
===
--- c-family/c.opt  (revision 180373)
+++ 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 180373)
+++ c-family/c-opts.c   (working copy)
@@ -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 

Re: [C++ Patch] PR 50810 (new try)

2011-10-24 Thread Gabriel Dos Reis
On Mon, Oct 24, 2011 at 7:18 AM, Paolo Carlini paolo.carl...@oracle.com wrote:
 Hi,

 On Mon, Oct 24, 2011 at 6:47 AM, Paolo Carlinipaolo.carl...@oracle.com
  wrote:

 Hi,

 the below is a new variant removing -Wc++0x-compat from -Wall (cannot be
 added to -Wextra either because bootstrap passes -W) and also, as
 requested
 by Gaby, preventing -Wno-narrowing from suppressing the warning in C++0x
 mode (if the user really needs to silence it, -Wno-c++0x-compat works). I
 also added a new testcase for that.

 OK with a minor correction.  This bit

 +With -std=c++0x, @option{-Wno-c++0x-compat} can be used to suppress
 +the diagnostic required by the standard.

 should not be there.  It is currently an accident of implementation
 detail as opposed to a feature.  It needs no advertisement.

 Ok. But I actively made it possible, if you want I can remove the
 possibility altogether, the patch also becomes cleaner ;)


Yes, I have been saying all long that -Wflag is not the way to
suppress a standard semantics.  So, if you can make the patch
cleaner without that, then the better! :-)


Re: [C++ Patch] PR 50810 (new try)

2011-10-24 Thread Jason Merrill

On 10/24/2011 07:47 AM, Paolo Carlini wrote:

the below is a new variant removing -Wc++0x-compat from -Wall (cannot be
added to -Wextra either because bootstrap passes -W)


I don't understand the rationale for this.  If the warning is 
problematic for bootstrap, why not just add -Wno-narrowing to the 
bootstrap warning flags?  I haven't read the whole discussion thread 
yet, though.



and also, as
requested by Gaby, preventing -Wno-narrowing from suppressing the
warning in C++0x mode (if the user really needs to silence it,
-Wno-c++0x-compat works). I also added a new testcase for that.


No.  I added -Wno-narrowing specifically to suppress the diagnostic in 
C++0x mode; see c++/49793.  There are several diagnostics required by 
standards that can be suppressed by -Wno- flags, such as -Wno-long-long.


Jason


Re: [C++ Patch] PR 50810 (new try)

2011-10-24 Thread Jason Merrill

On 10/24/2011 09:06 AM, Jason Merrill wrote:

On 10/24/2011 07:47 AM, Paolo Carlini wrote:

the below is a new variant removing -Wc++0x-compat from -Wall (cannot be
added to -Wextra either because bootstrap passes -W)


I don't understand the rationale for this. If the warning is problematic
for bootstrap, why not just add -Wno-narrowing to the bootstrap warning
flags? I haven't read the whole discussion thread yet, though.


OK, I read it and still think this is the right solution.


and also, as
requested by Gaby, preventing -Wno-narrowing from suppressing the
warning in C++0x mode (if the user really needs to silence it,
-Wno-c++0x-compat works). I also added a new testcase for that.


No. I added -Wno-narrowing specifically to suppress the diagnostic in
C++0x mode; see c++/49793. There are several diagnostics required by
standards that can be suppressed by -Wno- flags, such as -Wno-long-long.


...but I'm not strongly opposed to renaming the option, so long as its 
function remains.


Jason


Re: [C++ Patch] PR 50810 (new try)

2011-10-24 Thread Gabriel Dos Reis
On Mon, Oct 24, 2011 at 8:06 AM, Jason Merrill ja...@redhat.com wrote:
 On 10/24/2011 07:47 AM, Paolo Carlini wrote:
[...]
 and also, as
 requested by Gaby, preventing -Wno-narrowing from suppressing the
 warning in C++0x mode (if the user really needs to silence it,
 -Wno-c++0x-compat works). I also added a new testcase for that.

 No.  I added -Wno-narrowing specifically to suppress the diagnostic in C++0x
 mode; see c++/49793.  There are several diagnostics required by standards
 that can be suppressed by -Wno- flags, such as -Wno-long-long.

I do not think I follow.  The way we suppress a standard feature is through
a non-W flag.  -Wno-long-long should not have any effect at all in C++11.
It may have an effect in C++03.

-- Gaby


Re: [C++ Patch] PR 50810 (new try)

2011-10-24 Thread Jason Merrill

On 10/24/2011 09:26 AM, Gabriel Dos Reis wrote:

On Mon, Oct 24, 2011 at 8:06 AM, Jason Merrillja...@redhat.com  wrote:



No.  I added -Wno-narrowing specifically to suppress the diagnostic in C++0x
mode; see c++/49793.  There are several diagnostics required by standards
that can be suppressed by -Wno- flags, such as -Wno-long-long.


I do not think I follow.  The way we suppress a standard feature is through
a non-W flag.  -Wno-long-long should not have any effect at all in C++11.
It may have an effect in C++03.


Right, -Wno-long-long is only useful in C++03 and C90.  But it does in 
fact suppress a standard diagnostic.


Jason



Re: [C++ Patch] PR 50810 (new try)

2011-10-24 Thread Paolo Carlini
.. just to let you know guys, I'm already unassigned from the PR, but 
today I wanted to give it one (actually 3) more try. Given the 
controversy, I don't feel like further following the issue, it just 
makes me nervous. Eventually, feel free to adjust my patches to your likes.


Paolo.


Re: [C++ Patch] PR 50810 (new try)

2011-10-24 Thread Gabriel Dos Reis
On Mon, Oct 24, 2011 at 8:29 AM, Jason Merrill ja...@redhat.com wrote:
 On 10/24/2011 09:26 AM, Gabriel Dos Reis wrote:

 On Mon, Oct 24, 2011 at 8:06 AM, Jason Merrillja...@redhat.com  wrote:

 No.  I added -Wno-narrowing specifically to suppress the diagnostic in
 C++0x
 mode; see c++/49793.  There are several diagnostics required by standards
 that can be suppressed by -Wno- flags, such as -Wno-long-long.

 I do not think I follow.  The way we suppress a standard feature is
 through
 a non-W flag.  -Wno-long-long should not have any effect at all in C++11.
 It may have an effect in C++03.

 Right, -Wno-long-long is only useful in C++03 and C90.  But it does in fact
 suppress a standard diagnostic.

a diagnostic of an extension :-)

Similarly, -Wno-narrowing suppresses diagnostic in C++03 when -Wc++0x-compat
is in effect (therefore C++03).  However, just like -Wno-long-long, it
should not have
any effect when -std=c++0x or -std=c++11.


Re: [C++ Patch] PR 50810 (new try)

2011-10-24 Thread Jason Merrill

On 10/24/2011 09:49 AM, Gabriel Dos Reis wrote:

On Mon, Oct 24, 2011 at 8:29 AM, Jason Merrillja...@redhat.com  wrote:

Right, -Wno-long-long is only useful in C++03 and C90.  But it does in fact
suppress a standard diagnostic.


a diagnostic of an extension :-)


I'm not going to argue semantics any further.  What change do you 
suggest that still allows users to suppress narrowing diagnostics in C++11?


Jason


Re: [C++ Patch] PR 50810 (new try)

2011-10-24 Thread Gabriel Dos Reis
On Mon, Oct 24, 2011 at 9:10 AM, Jason Merrill ja...@redhat.com wrote:
 On 10/24/2011 09:49 AM, Gabriel Dos Reis wrote:

 On Mon, Oct 24, 2011 at 8:29 AM, Jason Merrillja...@redhat.com  wrote:

 Right, -Wno-long-long is only useful in C++03 and C90.  But it does in
 fact
 suppress a standard diagnostic.

 a diagnostic of an extension :-)

 I'm not going to argue semantics any further.  What change do you suggest
 that still allows users to suppress narrowing diagnostics in C++11?


Hmm, the narrowing semantics also affects SFINAE, not just simple declaration.
If we want a flag that can also affect the outcome of overload
resolution, it should
one of the the -fflags, such as -fpermissive.

-- Gaby


Re: [C++ Patch] PR 50810 (new try)

2011-10-24 Thread Jason Merrill

On 10/24/2011 10:39 AM, Gabriel Dos Reis wrote:

Hmm, the narrowing semantics also affects SFINAE, not just simple declaration.
If we want a flag that can also affect the outcome of overload
resolution, it should one of the the -fflags, such as -fpermissive.


I don't want the option to affect SFINAE, just suppress the diagnostic 
when tf_error is set.  There are a number of similar places in the 
compiler where if tf_error is set we give a pedwarn and accept the code, 
but if tf_error is not set we fail.


Jason


Re: [C++ Patch] PR 50810 (new try)

2011-10-24 Thread Gabriel Dos Reis
On Mon, Oct 24, 2011 at 9:53 AM, Jason Merrill ja...@redhat.com wrote:
 On 10/24/2011 10:39 AM, Gabriel Dos Reis wrote:

 Hmm, the narrowing semantics also affects SFINAE, not just simple
 declaration.
 If we want a flag that can also affect the outcome of overload
 resolution, it should one of the the -fflags, such as -fpermissive.

 I don't want the option to affect SFINAE,

So, let me recap:

  1. narrowing conversion is ill-formed in C++11; therefore a diagnostic
 is required.  This has two implications:
  a.  Normal scenario: a diagnostic is required and the program rejected.
   This is the one people complain about.

  b.  SFINAE context: because the narrowing is ill-formed, the offernding
   expression (rather, the offending function) would just be silently
   ignored; no diagnostic is actually output.


  2. -Wnarrowing warns about narrowing conversion, but does not reject
 the code.  This is only for C++98, C++03, with -Wc++0x-compat

While 1.b. looks like -Wnarrowing in sfinae context, it is not -Wno-narrowing
because with -Wnarrowing we still accept the expression (as opposed to
rejecting.)
So, if you make -Wno-narrowing meaningful in C++11 mode then how can
it not affect sfinae (case 1.b.) and still be consistent with the
other case where
a diagnostic is required  the expression accepted?


 just suppress the diagnostic when
 tf_error is set.  There are a number of similar places in the compiler where
 if tf_error is set we give a pedwarn and accept the code, but if tf_error is
 not set we fail.


Re: [C++ Patch] PR 50810 (new try)

2011-10-24 Thread Jason Merrill

On 10/24/2011 01:21 PM, Gabriel Dos Reis wrote:

On Mon, Oct 24, 2011 at 9:53 AM, Jason Merrillja...@redhat.com  wrote:
So, if you make -Wno-narrowing meaningful in C++11 mode then how can
it not affect sfinae (case 1.b.) and still be consistent with the
other case where a diagnostic is required the expression accepted?


Right, they will be inconsistent.  But that consistency isn't relevant 
for legacy code, which can't have list-initialization in SFINAE context.


Jason


Re: [C++ Patch] PR 50810 (new try)

2011-10-24 Thread Gabriel Dos Reis
On Mon, Oct 24, 2011 at 12:46 PM, Jason Merrill ja...@redhat.com wrote:
 On 10/24/2011 01:21 PM, Gabriel Dos Reis wrote:

 On Mon, Oct 24, 2011 at 9:53 AM, Jason Merrillja...@redhat.com  wrote:
 So, if you make -Wno-narrowing meaningful in C++11 mode then how can
 it not affect sfinae (case 1.b.) and still be consistent with the
 other case where a diagnostic is required the expression accepted?

 Right, they will be inconsistent.  But that consistency isn't relevant for
 legacy code, which can't have list-initialization in SFINAE context.

yes, but how does the compiler distinguish a legacy code compiled
under C++11 from non-legacy C++11 code?

I have no problem with C++03 codes.  I do not think they are affected.

The problem is with C++11 codes.  There is no reason for them to be subjected
to the inconsistency, especially for codes in header files that are
upgraded (beyond control of the end user) and included in legacy codes.
The legacy code may not have list-initialization in sfinae context, but
the upgraded header file may have, without the end user knowing.

It is wrong for a -Wflag to introduce that inconsistency in new codes.




Re: [C++ Patch] PR 50810 (new try)

2011-10-24 Thread Jason Merrill

On 10/24/2011 02:13 PM, Gabriel Dos Reis wrote:

yes, but how does the compiler distinguish a legacy code compiled
under C++11 from non-legacy C++11 code?


It doesn't.


The problem is with C++11 codes.  There is no reason for them to be subjected
to the inconsistency, especially for codes in header files that are
upgraded (beyond control of the end user) and included in legacy codes.
The legacy code may not have list-initialization in sfinae context, but
the upgraded header file may have, without the end user knowing.


And that header is unaffected.  Only initialization outside SFINAE 
context is affected.



It is wrong for a -Wflag to introduce that inconsistency in new codes.


What would you suggest instead?

Jason



Re: [C++ Patch] PR 50810 (new try)

2011-10-24 Thread Gabriel Dos Reis
On Mon, Oct 24, 2011 at 1:17 PM, Jason Merrill ja...@redhat.com wrote:
 On 10/24/2011 02:13 PM, Gabriel Dos Reis wrote:
 The problem is with C++11 codes.  There is no reason for them to be
 subjected
 to the inconsistency, especially for codes in header files that are
 upgraded (beyond control of the end user) and included in legacy codes.
 The legacy code may not have list-initialization in sfinae context, but
 the upgraded header file may have, without the end user knowing.

 And that header is unaffected.  Only initialization outside SFINAE context
 is affected.

I am afraid I do not understand why the header will
not be affected.

What about (testcase)

 int f(char);
 double f(...);

 const int n = sizeof f({257});

?

 It is wrong for a -Wflag to introduce that inconsistency in new codes.

 What would you suggest instead?

An -fflag.  If -fpermissive is too broad, then -flegacy-init or -flegacy


Re: [C++ Patch] PR 50810 (new try)

2011-10-24 Thread Jason Merrill

On 10/24/2011 02:47 PM, Gabriel Dos Reis wrote:

What about (testcase)

  int f(char);
  double f(...);

  const int n = sizeof f({257});

?


The narrowing conversion would be marked as 'bad' and therefore the 
second overload chosen.  As before, the objective is to only change the 
diagnostic, not the meaning of valid code.


Jason


Re: [C++ Patch] PR 50810 (new try)

2011-10-24 Thread Gabriel Dos Reis
On Mon, Oct 24, 2011 at 2:05 PM, Jason Merrill ja...@redhat.com wrote:
 On 10/24/2011 02:47 PM, Gabriel Dos Reis wrote:

 What about (testcase)

      int f(char);
      double f(...);

      const int n = sizeof f({257});

 ?

 The narrowing conversion would be marked as 'bad' and therefore the second
 overload chosen.  As before, the objective is to only change the diagnostic,
 not the meaning of valid code.


OK.  I think we may need better documentation of the behavior.


Re: [C++ Patch] PR 50810

2011-10-23 Thread Jason Merrill

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


Re: [C++ Patch] PR 50810

2011-10-23 Thread Paolo Carlini

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.

///
/c-family
2011-10-23  Paolo Carlini  paolo.carl...@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.carl...@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.carl...@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.carl...@oracle.com

PR c++/50810
* doc/invoke.texi ([-Wnarrowing], [-Wc++0x-compat]): Update.
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 

Re: [C++ Patch] PR 50810

2011-10-23 Thread Jason Merrill

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