re PR c++/66007 (Narrowing conversion inside { } results in all zero elements in C++11 mode with -Wno-error=narrowing)

/cp
2015-05-04  Paolo Carlini  <paolo.carlini@oracle.com>
	    Jakub Jelinek  <jakub@redhat.com>

	PR c++/66007
	* typeck2.c (check_narrowing): Check by-hand that the pedwarn didn't
	result in an actual error.

/testsuite
2015-05-04  Paolo Carlini  <paolo.carlini@oracle.com>
	    Jakub Jelinek  <jakub@redhat.com>

	PR c++/66007
	* g++.dg/cpp0x/Wnarrowing4.C: New.

Co-Authored-By: Jakub Jelinek <jakub@redhat.com>

From-SVN: r222778
This commit is contained in:
Paolo Carlini 2015-05-04 20:58:33 +00:00 committed by Paolo Carlini
parent 467d8d51f1
commit f5322614a6
4 changed files with 32 additions and 3 deletions

View File

@ -1,3 +1,10 @@
2015-05-04 Paolo Carlini <paolo.carlini@oracle.com>
Jakub Jelinek <jakub@redhat.com>
PR c++/66007
* typeck2.c (check_narrowing): Check by-hand that the pedwarn didn't
result in an actual error.
2015-05-01 Paolo Carlini <paolo.carlini@oracle.com> 2015-05-01 Paolo Carlini <paolo.carlini@oracle.com>
Prathamesh Kulharni <prathamesh.kulkarni@linaro.org> Prathamesh Kulharni <prathamesh.kulkarni@linaro.org>

View File

@ -958,10 +958,12 @@ check_narrowing (tree type, tree init, tsubst_flags_t complain)
} }
else if (complain & tf_error) else if (complain & tf_error)
{ {
int savederrorcount = errorcount;
global_dc->pedantic_errors = 1; global_dc->pedantic_errors = 1;
if (!pedwarn (EXPR_LOC_OR_LOC (init, input_location), OPT_Wnarrowing, pedwarn (EXPR_LOC_OR_LOC (init, input_location), OPT_Wnarrowing,
"narrowing conversion of %qE from %qT to %qT " "narrowing conversion of %qE from %qT to %qT "
"inside { }", init, ftype, type)) "inside { }", init, ftype, type);
if (errorcount == savederrorcount)
ok = true; ok = true;
global_dc->pedantic_errors = flag_pedantic_errors; global_dc->pedantic_errors = flag_pedantic_errors;
} }

View File

@ -1,3 +1,9 @@
2015-05-04 Paolo Carlini <paolo.carlini@oracle.com>
Jakub Jelinek <jakub@redhat.com>
PR c++/66007
* g++.dg/cpp0x/Wnarrowing4.C: New.
2015-05-04 Sandra Loosemore <sandra@codesourcery.com> 2015-05-04 Sandra Loosemore <sandra@codesourcery.com>
* lib/target-supports.exp * lib/target-supports.exp

View File

@ -0,0 +1,14 @@
// PR c++/66007
// { dg-do run { target c++11 } }
// { dg-options "-Wno-error=narrowing" }
extern "C" void abort();
int main()
{
unsigned foo[] = { 1, -1, 3 };
if (foo[0] != 1 || foo[1] != __INT_MAX__ * 2U + 1 || foo[2] != 3)
abort();
}
// { dg-prune-output "narrowing conversion" }