summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2014-08-09 08:58:33 +0000
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2014-08-09 08:58:33 +0000
commit718affe25d78d0e18b9c35ca25348c1ffaf1729a (patch)
tree6ee601ded83d4fe7b691e53061a78a56524ccec4
parent0ccbd52484034c8fe8e155d55deb860a05719a32 (diff)
downloadgcc-718affe25d78d0e18b9c35ca25348c1ffaf1729a.tar.gz
2014-08-09 Paolo Carlini <paolo.carlini@oracle.com>
* doc/invoke.texi ([Wnarrowing]): Update for non-constants in C++11. gcc/cp 2014-08-09 Paolo Carlini <paolo.carlini@oracle.com> * typeck2.c (check_narrowing): Add tsubst_flags_t parameter, change return type to bool; in C++11 for constants give errors, not pedwarns. * cp-tree.h (check_narrowing): Adjust declaration. * call.c (convert_like_real): Update calls. * semantics.c (finish_compound_literal): Likewise. gcc/testsuite 2014-08-09 Paolo Carlini <paolo.carlini@oracle.com> * g++.dg/cpp0x/Wnarrowing1.C: Adjust for errors. * g++.dg/cpp0x/enum29.C: Adjust. /libstdc++-v3 2014-08-09 Paolo Carlini <paolo.carlini@oracle.com> * include/ext/pod_char_traits.h (char_traits<__gnu_cxx:: character<_Value, _Int, _St> >::eof): Fix vs narrowing conversion. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@213776 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog23
-rw-r--r--gcc/cp/ChangeLog8
-rw-r--r--gcc/cp/call.c10
-rw-r--r--gcc/cp/cp-tree.h2
-rw-r--r--gcc/cp/semantics.c4
-rw-r--r--gcc/cp/typeck2.c42
-rw-r--r--gcc/doc/invoke.texi8
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/Wnarrowing1.C8
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/enum29.C2
-rw-r--r--libstdc++-v3/ChangeLog5
-rw-r--r--libstdc++-v3/include/ext/pod_char_traits.h4
12 files changed, 81 insertions, 40 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index c58827ed9ce..2aa721c9ce2 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,7 @@
+2014-08-09 Paolo Carlini <paolo.carlini@oracle.com>
+
+ * doc/invoke.texi ([Wnarrowing]): Update for non-constants in C++11.
+
2014-08-09 Roman Gareev <gareevroman@gmail.com>
* graphite-isl-ast-to-gimple.c:
@@ -20,7 +24,6 @@
* predict.c (expr_expected_value_1): Remove the redundant assignment.
-
2014-08-08 Richard Biener <rguenther@suse.de>
* lto-streamer.h (struct lto_input_block): Make it a class
@@ -289,7 +292,7 @@
2014-08-07 Marek Polacek <polacek@redhat.com>
- * fold-const.c (fold_binary_loc): Add folding of
+ * fold-const.c (fold_binary_loc): Add folding of
(PTR0 - (PTR1 p+ A) -> (PTR0 - PTR1) - A.
2013-08-07 Ilya Enkovich <ilya.enkovich@intel.com>
@@ -477,10 +480,10 @@
2014-08-05 Roman Gareev <gareevroman@gmail.com>
* graphite-isl-ast-to-gimple.c: Add a new struct ast_build_info.
- (translate_isl_ast_for_loop): Add checking of the
+ (translate_isl_ast_for_loop): Add checking of the
flag_loop_parallelize_all.
(ast_build_before_for): New function.
- (scop_to_isl_ast): Add checking of the
+ (scop_to_isl_ast): Add checking of the
flag_loop_parallelize_all.
* graphite-dependences.c: Move the defenition of the
scop_get_dependences from graphite-optimize-isl.c to this file.
@@ -612,7 +615,8 @@
2014-08-01 Jan Hubicka <hubicka@ucw.cz>
- * doc/invoke.texi (Wsuggest-final-types, Wsuggest-final-methods): Document.
+ * doc/invoke.texi (Wsuggest-final-types, Wsuggest-final-methods):
+ Document.
* ipa-devirt.c: Include hash-map.h
(struct polymorphic_call_target_d): Add type_warning and decl_warning.
(clear_speculation): Break out of ...
@@ -621,15 +625,16 @@
(odr_type_warn_count, decl_warn_count): New structures.
(final_warning_record): New structure.
(final_warning_records): New static variable.
- (possible_polymorphic_call_targets): Cleanup handling of speculative info;
- do not build speculation when user do not care; record info about warnings
- when asked for.
+ (possible_polymorphic_call_targets): Cleanup handling of
+ speculative info; do not build speculation when user do not care;
+ record info about warnings when asked for.
(add_decl_warning): New function.
(type_warning_cmp): New function.
(decl_warning_cmp): New function.
(ipa_devirt): Handle -Wsuggest-final-methods and -Wsuggest-final-types.
(gate): Enable pass when warnings are requested.
- * common.opt (Wsuggest-final-types, Wsuggest-final-methods): New options.
+ * common.opt (Wsuggest-final-types, Wsuggest-final-methods): New
+ options.
2014-08-02 Trevor Saunders <tsaunders@mozilla.com>
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 6d3eda2651f..47621ca0e86 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,11 @@
+2014-08-09 Paolo Carlini <paolo.carlini@oracle.com>
+
+ * typeck2.c (check_narrowing): Add tsubst_flags_t parameter, change
+ return type to bool; in C++11 for constants give errors, not pedwarns.
+ * cp-tree.h (check_narrowing): Adjust declaration.
+ * call.c (convert_like_real): Update calls.
+ * semantics.c (finish_compound_literal): Likewise.
+
2014-08-08 Jason Merrill <jason@redhat.com>
* pt.c (lookup_template_class_1): Copy abi_tag.
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 4d37c65209f..64cab453ae0 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -6251,8 +6251,9 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
1, false, false, complain);
if (sub == error_mark_node)
return sub;
- if (!BRACE_ENCLOSED_INITIALIZER_P (val))
- check_narrowing (TREE_TYPE (sub), val);
+ if (!BRACE_ENCLOSED_INITIALIZER_P (val)
+ && !check_narrowing (TREE_TYPE (sub), val, complain))
+ return error_mark_node;
CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_ctor), NULL_TREE, sub);
if (!TREE_CONSTANT (sub))
TREE_CONSTANT (new_ctor) = false;
@@ -6480,8 +6481,9 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
break;
}
- if (convs->check_narrowing)
- check_narrowing (totype, expr);
+ if (convs->check_narrowing
+ && !check_narrowing (totype, expr, complain))
+ return error_mark_node;
if (issue_conversion_warnings)
expr = cp_convert_and_check (totype, expr, complain);
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index ec79c232ec6..64049c403d2 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -6214,7 +6214,7 @@ extern int abstract_virtuals_error_sfinae (tree, tree, tsubst_flags_t);
extern int abstract_virtuals_error_sfinae (abstract_class_use, tree, tsubst_flags_t);
extern tree store_init_value (tree, tree, vec<tree, va_gc>**, int);
-extern void check_narrowing (tree, tree);
+extern bool check_narrowing (tree, tree, tsubst_flags_t);
extern tree digest_init (tree, tree, tsubst_flags_t);
extern tree digest_init_flags (tree, tree, int);
extern tree digest_nsdmi_init (tree, tree);
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 63365c70e1a..531927e3bca 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -2597,8 +2597,8 @@ finish_compound_literal (tree type, tree compound_literal,
compound_literal = reshape_init (type, compound_literal, complain);
if (SCALAR_TYPE_P (type)
&& !BRACE_ENCLOSED_INITIALIZER_P (compound_literal)
- && (complain & tf_warning_or_error))
- check_narrowing (type, compound_literal);
+ && !check_narrowing (type, compound_literal, complain))
+ return error_mark_node;
if (TREE_CODE (type) == ARRAY_TYPE
&& TYPE_DOMAIN (type) == NULL_TREE)
{
diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c
index 20523faf09b..c985a4bf92c 100644
--- a/gcc/cp/typeck2.c
+++ b/gcc/cp/typeck2.c
@@ -842,27 +842,31 @@ store_init_value (tree decl, tree init, vec<tree, va_gc>** cleanups, int flags)
}
-/* Give errors about narrowing conversions within { }. */
+/* Give diagnostic about narrowing conversions within { }. */
-void
-check_narrowing (tree type, tree init)
+bool
+check_narrowing (tree type, tree init, tsubst_flags_t complain)
{
tree ftype = unlowered_expr_type (init);
bool ok = true;
REAL_VALUE_TYPE d;
- if (!warn_narrowing || !ARITHMETIC_TYPE_P (type))
- return;
+ if (((!warn_narrowing || !(complain & tf_warning))
+ && cxx_dialect == cxx98)
+ || !ARITHMETIC_TYPE_P (type))
+ return ok;
if (BRACE_ENCLOSED_INITIALIZER_P (init)
&& TREE_CODE (type) == COMPLEX_TYPE)
{
tree elttype = TREE_TYPE (type);
if (CONSTRUCTOR_NELTS (init) > 0)
- check_narrowing (elttype, CONSTRUCTOR_ELT (init, 0)->value);
+ ok &= check_narrowing (elttype, CONSTRUCTOR_ELT (init, 0)->value,
+ complain);
if (CONSTRUCTOR_NELTS (init) > 1)
- check_narrowing (elttype, CONSTRUCTOR_ELT (init, 1)->value);
- return;
+ ok &= check_narrowing (elttype, CONSTRUCTOR_ELT (init, 1)->value,
+ complain);
+ return ok;
}
init = maybe_constant_value (fold_non_dependent_expr_sfinae (init, tf_none));
@@ -917,15 +921,27 @@ check_narrowing (tree type, tree init)
if (!ok)
{
- if (cxx_dialect >= cxx11)
- pedwarn (EXPR_LOC_OR_LOC (init, input_location), OPT_Wnarrowing,
- "narrowing conversion of %qE from %qT to %qT inside { }",
- init, ftype, type);
- else
+ if (cxx_dialect == cxx98)
warning_at (EXPR_LOC_OR_LOC (init, input_location), OPT_Wnarrowing,
"narrowing conversion of %qE from %qT to %qT inside { } "
"is ill-formed in C++11", init, ftype, type);
+ else if (!TREE_CONSTANT (init))
+ {
+ if (complain & tf_warning_or_error)
+ {
+ pedwarn (EXPR_LOC_OR_LOC (init, input_location), OPT_Wnarrowing,
+ "narrowing conversion of %qE from %qT to %qT inside { }",
+ init, ftype, type);
+ ok = true;
+ }
+ }
+ else if (complain & tf_error)
+ error_at (EXPR_LOC_OR_LOC (init, input_location),
+ "narrowing conversion of %qE from %qT to %qT inside { }",
+ init, ftype, type);
}
+
+ return cxx_dialect == cxx98 || ok;
}
/* Process the initializer INIT for a variable of type TYPE, emitting
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 4f327df69eb..35820350d6c 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -2622,10 +2622,10 @@ int i = @{ 2.2 @}; // error: narrowing from double to int
This flag is included in @option{-Wall} and @option{-Wc++11-compat}.
-With @option{-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.
+With @option{-std=c++11}, @option{-Wno-narrowing} suppresses for
+non-constants 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
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index bd881d33d47..073f83780b8 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2014-08-09 Paolo Carlini <paolo.carlini@oracle.com>
+
+ * g++.dg/cpp0x/Wnarrowing1.C: Adjust for errors.
+ * g++.dg/cpp0x/enum29.C: Adjust.
+
2014-08-08 Richard Biener <rguenther@suse.de>
* gcc.dg/strlenopt-8.c: Remove XFAIL.
diff --git a/gcc/testsuite/g++.dg/cpp0x/Wnarrowing1.C b/gcc/testsuite/g++.dg/cpp0x/Wnarrowing1.C
index 634c4c377d0..4df30255474 100644
--- a/gcc/testsuite/g++.dg/cpp0x/Wnarrowing1.C
+++ b/gcc/testsuite/g++.dg/cpp0x/Wnarrowing1.C
@@ -9,10 +9,10 @@ struct X
int f() { return __INT_MAX__; }
-signed char a { __INT_MAX__ }; // { dg-warning "narrowing conversion" }
+signed char a { __INT_MAX__ }; // { dg-error "narrowing conversion" }
signed char b { f() }; // { dg-warning "narrowing conversion" }
-signed char c { X{} }; // { dg-warning "narrowing conversion" }
+signed char c { X{} }; // { dg-error "narrowing conversion" }
-signed char ar[] { __INT_MAX__ }; // { dg-warning "narrowing conversion" }
+signed char ar[] { __INT_MAX__ }; // { dg-error "narrowing conversion" }
signed char br[] { f() }; // { dg-warning "narrowing conversion" }
-signed char cr[] { X{} }; // { dg-warning "narrowing conversion" }
+signed char cr[] { X{} }; // { dg-error "narrowing conversion" }
diff --git a/gcc/testsuite/g++.dg/cpp0x/enum29.C b/gcc/testsuite/g++.dg/cpp0x/enum29.C
index 43a99aee673..f24a6a2a958 100644
--- a/gcc/testsuite/g++.dg/cpp0x/enum29.C
+++ b/gcc/testsuite/g++.dg/cpp0x/enum29.C
@@ -51,8 +51,6 @@ enum F5 : int { f5 = X5() };
enum G0 : signed char { g0 = X0() };
enum G1 : signed char { g1 = X1() };
enum G2 : signed char { g2 = X2() }; // { dg-error "narrowing" }
-// { dg-warning "overflow" "" { target *-*-* } 53 }
enum G3 : signed char { g3 = X3() }; // { dg-error "narrowing" }
-// { dg-warning "overflow" "" { target *-*-* } 55 }
enum G4 : signed char { g4 = X4() }; // { dg-error "narrowing" }
enum G5 : signed char { g5 = X5() }; // { dg-error "ambiguous" }
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index bd8677ec473..821dfe5c874 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,8 @@
+2014-08-08 Paolo Carlini <paolo.carlini@oracle.com>
+
+ * include/ext/pod_char_traits.h (char_traits<__gnu_cxx::
+ character<_Value, _Int, _St> >::eof): Fix vs narrowing conversion.
+
2014-08-09 François Dumont <fdumont@gcc.gnu.org>
PR libstdc++/61667
diff --git a/libstdc++-v3/include/ext/pod_char_traits.h b/libstdc++-v3/include/ext/pod_char_traits.h
index e027585e704..d6de298a90f 100644
--- a/libstdc++-v3/include/ext/pod_char_traits.h
+++ b/libstdc++-v3/include/ext/pod_char_traits.h
@@ -177,7 +177,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
static int_type
eof()
{
- int_type __r = { -1 };
+ int_type __r = { static_cast<typename __gnu_cxx::__conditional_type
+ <std::__is_integer<int_type>::__value,
+ int_type, int>::__type>(-1) };
return __r;
}